59 #include <sys/select.h>
60 #include <sys/types.h>
63 #include <libxml/tree.h>
64 #include <libxml/parser.h>
65 #include <libxml/xpath.h>
66 #include <libxml/xpathInternals.h>
67 #include <libxml/relaxng.h>
82 #if defined(HAVE_SYSLOG_R) && defined(HAVE_OPENLOG_R) && defined(HAVE_CLOSELOG_R) && defined(HAVE_VSYSLOG_R)
83 struct syslog_data sdata = SYSLOG_DATA_INIT;
87 #undef HAVE_CLOSELOG_R
97 xmlDocPtr rngdoc = NULL;
98 xmlXPathContextPtr xpathCtx = NULL;
99 xmlXPathObjectPtr xpathObj = NULL;
100 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
101 xmlRelaxNGValidCtxtPtr rngctx = NULL;
102 xmlRelaxNGPtr schema = NULL;
103 xmlChar *user_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/User";
104 xmlChar *group_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/Group";
106 char* filename = NULL;
107 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
108 char* temp_char = NULL;
118 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
122 doc = xmlParseFile(filename);
125 file = fopen(filename,
"r");
127 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
129 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
136 rngdoc = xmlParseFile(rngfilename);
137 if (rngdoc == NULL) {
139 file = fopen(rngfilename,
"r");
141 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
143 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
150 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
151 if (rngpctx == NULL) {
152 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
157 schema = xmlRelaxNGParse(rngpctx);
158 if (schema == NULL) {
159 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
164 rngctx = xmlRelaxNGNewValidCtxt(schema);
165 if (rngctx == NULL) {
166 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
170 xmlRelaxNGSetValidErrors(rngctx,
176 status = xmlRelaxNGValidateDoc(rngctx,doc);
178 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
184 xpathCtx = xmlXPathNewContext(doc);
185 if(xpathCtx == NULL) {
186 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
192 xpathObj = xmlXPathEvalExpression(group_expr, xpathCtx);
193 if(xpathObj == NULL) {
194 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", group_expr);
195 xmlXPathFreeContext(xpathCtx);
199 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
200 temp_char = (
char*) xmlXPathCastToString(xpathObj);
203 xmlXPathFreeObject(xpathObj);
209 xpathObj = xmlXPathEvalExpression(user_expr, xpathCtx);
210 if(xpathObj == NULL) {
211 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", user_expr);
212 xmlXPathFreeContext(xpathCtx);
216 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
217 temp_char = (
char*) xmlXPathCastToString(xpathObj);
220 xmlXPathFreeObject(xpathObj);
228 if ((pwd = getpwnam(config->
username)) == NULL) {
230 syslog_r(LOG_ERR, &sdata,
"user '%s' does not exist. exiting...\n", config->
username);
232 syslog(LOG_ERR,
"user '%s' does not exist. exiting...\n", config->
username);
236 config->
uid = pwd->pw_uid;
242 if ((grp = getgrnam(config->
groupname)) == NULL) {
244 syslog_r(LOG_ERR, &sdata,
"group '%s' does not exist. exiting...\n", config->
groupname);
246 syslog(LOG_ERR,
"group '%s' does not exist. exiting...\n", config->
groupname);
250 config->
gid = grp->gr_gid;
255 xmlXPathFreeContext(xpathCtx);
256 xmlRelaxNGFree(schema);
257 xmlRelaxNGFreeValidCtxt(rngctx);
258 xmlRelaxNGFreeParserCtxt(rngpctx);
267 void log_init(
int facility,
const char *program_name)
269 #ifdef HAVE_OPENLOG_R
270 openlog_r(program_name, 0, facility, &sdata);
272 openlog(program_name, 0, facility);
277 void log_switch(
int facility,
const char *facility_name,
const char *program_name,
int verbose)
279 #ifdef HAVE_CLOSELOG_R
284 #ifdef HAVE_OPENLOG_R
285 openlog_r(program_name, 0, facility, &sdata);
287 openlog(program_name, 0, facility);
290 log_msg(NULL, LOG_INFO,
"Switched log facility to: %s", facility_name);
300 if (config && config->
debug) priority = LOG_ERR;
301 va_start(args, format);
302 #ifdef HAVE_VSYSLOG_R
303 vsyslog_r(priority, &sdata, format, args);
305 vsyslog(priority, format, args);
316 if (strncmp(format,
"ERROR:", 6) == 0) {
318 syslog_r(LOG_ERR, &sdata,
"%s", format);
320 syslog(LOG_ERR,
"%s", format);
323 else if (strncmp(format,
"INFO:", 5) == 0) {
325 syslog_r(LOG_INFO, &sdata,
"%s", format);
327 syslog(LOG_INFO,
"%s", format);
330 else if (strncmp(format,
"WARNING:", 8) == 0) {
332 syslog_r(LOG_WARNING, &sdata,
"%s", format);
334 syslog(LOG_WARNING,
"%s", format);
337 else if (strncmp(format,
"DEBUG:", 6) == 0) {
339 syslog_r(LOG_DEBUG, &sdata,
"%s", format);
341 syslog(LOG_DEBUG,
"%s", format);
346 syslog_r(LOG_ERR, &sdata,
"%s", format);
348 syslog(LOG_ERR,
"%s", format);
362 va_start(args, format);
363 #ifdef HAVE_VSYSLOG_R
364 vsyslog_r(LOG_ERR, &sdata, format, args);
366 vsyslog(LOG_ERR, format, args);
380 va_start(args, format);
381 #ifdef HAVE_VSYSLOG_R
382 vsyslog_r(LOG_INFO, &sdata, format, args);
384 vsyslog(LOG_INFO, format, args);
390 usage(
const char* prog)
392 fprintf(stderr,
"Usage: %s [OPTION]...\n", prog);
393 fprintf(stderr,
"OpenDNSSEC Enforcer version %s\n\n", VERSION);
394 fprintf(stderr,
"Supported options:\n");
395 fprintf(stderr,
" -c <file> Use alternate conf.xml.\n");
396 fprintf(stderr,
" -d Debug.\n");
397 fprintf(stderr,
" -1 Run once, then exit.\n");
398 fprintf(stderr,
" -p <policy> Run once processing only the specified policy, then exit.\n");
400 fprintf(stderr,
" -P <pidfile> Specify the PID file to write.\n");
402 fprintf(stderr,
" -V Print version.\n");
403 fprintf(stderr,
" -[?|h] This help.\n");
409 fprintf(stderr,
"%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
410 fprintf(stderr,
"Written by %s.\n\n",
AUTHOR_NAME);
411 fprintf(stderr,
"%s. This is free software.\n",
COPYRIGHT_STR);
412 fprintf(stderr,
"See source files for more license information\n");
424 result = fwrite(data, 1, size, file);
427 log_msg(config, LOG_ERR,
"write failed: %s", strerror(errno));
429 }
else if (result < size) {
430 log_msg(config, LOG_ERR,
"short write (disk full?)");
438 readpid(
const char *file)
446 if ((fd = open(file, O_RDONLY)) == -1) {
449 if (((l = read(fd, pidbuf,
sizeof(pidbuf)))) == -1) {
459 pid = strtol(pidbuf, &t, 10);
461 if (*t && *t !=
'\n') {
472 struct stat stat_ret;
477 if (stat(config->
pidfile, &stat_ret) != 0) {
479 if (errno != ENOENT) {
480 log_msg(config, LOG_ERR,
"cannot stat pidfile %s: %s",
481 config->
pidfile, strerror(errno));
485 if (S_ISREG(stat_ret.st_mode)) {
487 if ((oldpid = readpid(config->
pidfile)) == -1) {
489 if (errno != ENOENT) {
490 log_msg(config, LOG_ERR,
"cannot read pidfile %s: %s",
491 config->
pidfile, strerror(errno));
494 if (kill(oldpid, 0) == 0 || errno == EPERM) {
495 log_msg(config, LOG_ERR,
"pidfile %s already exists, "
496 "a process with pid %u is already running. "
497 "If no ods-enforcerd process is running, a previous "
498 "instance didn't shutdown cleanly, please remove this "
499 "file and try again.", config->
pidfile, oldpid);
502 log_msg(config, LOG_WARNING,
"pidfile %s already exists, "
503 "but no process with pid %u is running. "
504 "A previous instance didn't shutdown cleanly, this "
505 "pidfile is stale.", config->
pidfile, oldpid);
512 snprintf(pidbuf,
sizeof(pidbuf),
"%lu\n", (
unsigned long) config->
pid);
514 if ((fd = fopen(config->
pidfile,
"w")) == NULL ) {
518 if (!
write_data(config, fd, pidbuf, strlen(pidbuf))) {
524 if (chown(config->
pidfile, config->
uid, config->
gid) == -1) {
525 log_msg(config, LOG_ERR,
"cannot chown(%u,%u) %s: %s",
526 (
unsigned) config->
uid, (
unsigned) config->
gid,
527 config->
pidfile, strerror(errno));
539 char* directory = NULL;
541 struct stat stat_ret;
542 char *path = getenv(
"PWD");
552 slash = strrchr(directory,
'/');
556 if (stat(directory, &stat_ret) != 0) {
558 if (errno != ENOENT) {
559 log_msg(config, LOG_ERR,
"cannot stat directory %s: %s",
560 directory, strerror(errno));
565 if (S_ISDIR(stat_ret.st_mode)) {
583 struct stat stat_ret;
586 slash = strrchr(parent,
'/');
590 stat(parent, &stat_ret);
592 if (!S_ISDIR(stat_ret.st_mode)) {
600 if (mkdir(path, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != 0) {
601 log_msg(NULL, LOG_ERR,
"cannot create directory %s: %s\n",
602 path, strerror(errno));
607 if (chown(path, config->
uid, config->
gid) == -1) {
608 log_msg(config, LOG_ERR,
"cannot chown(%u,%u) %s: %s",
609 (
unsigned) config->
uid, (
unsigned) config->
gid,
610 path, strerror(errno));
626 while ((c = getopt(*argc, argv,
"1c:hdV?u:P:p:")) != -1) {
635 config->
debug =
true;
644 config->
gid = getgid();
645 config->
uid = getuid();
652 if (*t !=
'.' || !isdigit(*++t)) {
653 log_msg(config, LOG_ERR,
"-u user or -u uid or -u uid.gid. exiting...");
656 config->
gid = strtol(t, &t, 10);
659 if ((pwd = getpwuid(config->
uid)) == NULL) {
660 log_msg(config, LOG_ERR,
"user id %u does not exist. exiting...", (
unsigned) config->
uid);
663 config->
gid = pwd->pw_gid;
669 if ((pwd = getpwnam(config->
username)) == NULL) {
670 log_msg(config, LOG_ERR,
"user '%s' does not exist. exiting...", config->
username);
673 config->
uid = pwd->pw_uid;
674 config->
gid = pwd->pw_gid;
683 fprintf(stdout,
"Will only process policy \"%s\", will only run once. Check the logs for results. \n", config->
policy);
709 xmlDocPtr doc = NULL;
710 xmlDocPtr rngdoc = NULL;
711 xmlXPathContextPtr xpathCtx = NULL;
712 xmlXPathObjectPtr xpathObj = NULL;
713 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
714 xmlRelaxNGValidCtxtPtr rngctx = NULL;
715 xmlRelaxNGPtr schema = NULL;
716 xmlChar *iv_expr = (
unsigned char*)
"//Configuration/Enforcer/Interval";
717 xmlChar *mk_expr = (
unsigned char*)
"//Configuration/Enforcer/ManualKeyGeneration";
718 xmlChar *rn_expr = (
unsigned char*)
"//Configuration/Enforcer/RolloverNotification";
719 xmlChar *ds_expr = (
unsigned char*)
"//Configuration/Enforcer/DelegationSignerSubmitCommand";
720 xmlChar *litexpr = (
unsigned char*)
"//Configuration/Enforcer/Datastore/SQLite";
721 xmlChar *mysql_host = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host";
722 xmlChar *mysql_port = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host/@port";
723 xmlChar *mysql_db = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Database";
724 xmlChar *mysql_user = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Username";
725 xmlChar *mysql_pass = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Password";
726 xmlChar *log_user_expr = (
unsigned char*)
"//Configuration/Common/Logging/Syslog/Facility";
729 char *logFacilityName;
733 char* filename = NULL;
734 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
736 char* temp_char = NULL;
744 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
748 log_msg(config, LOG_INFO,
"Reading config \"%s\"", filename);
752 doc = xmlParseFile(filename);
755 file = fopen(filename,
"r");
757 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
759 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
767 log_msg(config, LOG_INFO,
"Reading config schema \"%s\"", rngfilename);
769 rngdoc = xmlParseFile(rngfilename);
770 if (rngdoc == NULL) {
772 file = fopen(rngfilename,
"r");
774 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
776 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
783 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
784 if (rngpctx == NULL) {
785 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
790 schema = xmlRelaxNGParse(rngpctx);
791 if (schema == NULL) {
792 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
797 rngctx = xmlRelaxNGNewValidCtxt(schema);
798 if (rngctx == NULL) {
799 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
803 xmlRelaxNGSetValidErrors(rngctx,
809 status = xmlRelaxNGValidateDoc(rngctx,doc);
811 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
814 xmlRelaxNGFreeValidCtxt(rngctx);
815 xmlRelaxNGFree(schema);
816 xmlRelaxNGFreeParserCtxt(rngpctx);
821 xpathCtx = xmlXPathNewContext(doc);
822 if(xpathCtx == NULL) {
823 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
829 xpathObj = xmlXPathEvalExpression(iv_expr, xpathCtx);
830 if(xpathObj == NULL) {
831 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", iv_expr);
832 xmlXPathFreeContext(xpathCtx);
837 temp_char = (
char *)xmlXPathCastToString(xpathObj);
840 log_msg(config, LOG_ERR,
"Error: unable to convert Interval %s to seconds, error: %i", temp_char, status);
844 else if (status == -1) {
845 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
849 log_msg(config, LOG_INFO,
"Communication Interval: %i", config->
interval);
852 xmlXPathFreeObject(xpathObj);
855 xpathObj = xmlXPathEvalExpression(mk_expr, xpathCtx);
856 if(xpathObj == NULL) {
857 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mk_expr);
858 xmlXPathFreeContext(xpathCtx);
863 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
871 xmlXPathFreeObject(xpathObj);
874 xpathObj = xmlXPathEvalExpression(rn_expr, xpathCtx);
875 if(xpathObj == NULL) {
876 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", rn_expr);
877 xmlXPathFreeContext(xpathCtx);
882 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
884 temp_char = (
char *)xmlXPathCastToString(xpathObj);
887 log_msg(config, LOG_ERR,
"Error: unable to convert RolloverNotification %s to seconds, error: %i", temp_char, status);
891 else if (status == -1) {
892 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
899 xmlXPathFreeObject(xpathObj);
907 xpathObj = xmlXPathEvalExpression(ds_expr, xpathCtx);
908 if(xpathObj == NULL) {
909 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", ds_expr);
910 xmlXPathFreeContext(xpathCtx);
914 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
919 config->
DSSubmitCmd = (
char *)xmlXPathCastToString(xpathObj);
922 log_msg(config, LOG_INFO,
"Using command: %s to submit DS records", config->
DSSubmitCmd);
924 xmlXPathFreeObject(xpathObj);
927 log_msg(config, LOG_INFO,
"No DS Submit command supplied");
934 xpathObj = xmlXPathEvalExpression(litexpr, xpathCtx);
935 if(xpathObj == NULL) {
936 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", litexpr);
937 xmlXPathFreeContext(xpathCtx);
941 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
943 if (config->
schema != NULL) {
946 config->
schema = xmlXPathCastToString(xpathObj);
948 log_msg(config, LOG_INFO,
"SQLite database set to: %s", config->
schema);
951 xmlXPathFreeObject(xpathObj);
958 xpathObj = xmlXPathEvalExpression(mysql_host, xpathCtx);
959 if(xpathObj == NULL) {
960 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_host);
961 xmlXPathFreeContext(xpathCtx);
965 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
966 if (config->
host != NULL) {
969 config->
host = xmlXPathCastToString(xpathObj);
971 log_msg(config, LOG_INFO,
"MySQL database host set to: %s", config->
host);
974 xmlXPathFreeObject(xpathObj);
977 xpathObj = xmlXPathEvalExpression(mysql_port, xpathCtx);
978 if(xpathObj == NULL) {
979 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_port);
980 xmlXPathFreeContext(xpathCtx);
984 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
985 if (config->
port != NULL) {
988 config->
port = xmlXPathCastToString(xpathObj);
990 log_msg(config, LOG_INFO,
"MySQL database port set to: %s", config->
port);
993 xmlXPathFreeObject(xpathObj);
996 xpathObj = xmlXPathEvalExpression(mysql_db, xpathCtx);
997 if(xpathObj == NULL) {
998 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_db);
999 xmlXPathFreeContext(xpathCtx);
1003 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1004 if (config->
schema != NULL) {
1007 config->
schema = xmlXPathCastToString(xpathObj);
1009 log_msg(config, LOG_INFO,
"MySQL database schema set to: %s", config->
schema);
1014 xmlXPathFreeObject(xpathObj);
1017 xpathObj = xmlXPathEvalExpression(mysql_user, xpathCtx);
1018 if(xpathObj == NULL) {
1019 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_user);
1020 xmlXPathFreeContext(xpathCtx);
1024 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1025 if (config->
user != NULL) {
1028 config->
user = xmlXPathCastToString(xpathObj);
1030 log_msg(config, LOG_INFO,
"MySQL database user set to: %s", config->
user);
1035 xmlXPathFreeObject(xpathObj);
1038 xpathObj = xmlXPathEvalExpression(mysql_pass, xpathCtx);
1039 if(xpathObj == NULL) {
1040 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_pass);
1041 xmlXPathFreeContext(xpathCtx);
1050 config->
password = xmlXPathCastToString(xpathObj);
1052 log_msg(config, LOG_INFO,
"MySQL database password set");
1054 xmlXPathFreeObject(xpathObj);
1060 log_msg(config, LOG_ERR,
"Error: unable to find complete database connection expression in %s", filename);
1061 xmlXPathFreeContext(xpathCtx);
1068 log_msg(config, LOG_ERR,
"Error: database in config file %s does not match libksm", filename);
1069 xmlXPathFreeContext(xpathCtx);
1075 xpathObj = xmlXPathEvalExpression(log_user_expr, xpathCtx);
1076 if(xpathObj == NULL) {
1077 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", log_user_expr);
1078 xmlXPathFreeContext(xpathCtx);
1083 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1085 logFacilityName = (
char *)xmlXPathCastToString(xpathObj);
1089 log_msg(config, LOG_ERR,
"Error: unable to set log user: %s, error: %i", logFacilityName, status);
1095 log_msg(config, LOG_INFO,
"Log User set to: %s", logFacilityName);
1103 log_msg(config, LOG_INFO,
"Using default log user: %s", logFacilityName);
1107 xmlXPathFreeObject(xpathObj);
1113 xmlXPathFreeContext(xpathCtx);
1133 if (lock_fd == NULL) {
1134 log_msg(NULL, LOG_ERR,
"%s could not be opened", lock_filename);
1138 memset(&fl, 0,
sizeof(
struct flock));
1139 fl.l_type = F_WRLCK;
1140 fl.l_whence = SEEK_SET;
1141 fl.l_pid = getpid();
1143 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1144 if (errno == EACCES || errno == EAGAIN) {
1145 log_msg(NULL, LOG_INFO,
"%s already locked, sleep", lock_filename);
1150 select(0, NULL, NULL, NULL, &tv);
1153 log_msg(NULL, LOG_INFO,
"couldn't get lock on %s, %s", lock_filename, strerror(errno));
1166 if (lock_fd == NULL) {
1170 memset(&fl, 0,
sizeof(
struct flock));
1171 fl.l_type = F_UNLCK;
1172 fl.l_whence = SEEK_SET;
1174 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1184 char* case_username = NULL;
1186 if (username == NULL) {
1196 if (strncmp(case_username,
"USER", 4) == 0) {
1197 *usernumber = LOG_USER;
1200 else if (strncmp(case_username,
"KERN", 4) == 0) {
1201 *usernumber = LOG_KERN;
1205 else if (strncmp(case_username,
"MAIL", 4) == 0) {
1206 *usernumber = LOG_MAIL;
1210 else if (strncmp(case_username,
"DAEMON", 6) == 0) {
1211 *usernumber = LOG_DAEMON;
1215 else if (strncmp(case_username,
"AUTH", 4) == 0) {
1216 *usernumber = LOG_AUTH;
1220 else if (strncmp(case_username,
"SYSLOG", 6) == 0) {
1221 *usernumber = LOG_SYSLOG;
1225 else if (strncmp(case_username,
"LPR", 3) == 0) {
1226 *usernumber = LOG_LPR;
1230 else if (strncmp(case_username,
"NEWS", 4) == 0) {
1231 *usernumber = LOG_NEWS;
1235 else if (strncmp(case_username,
"UUCP", 4) == 0) {
1236 *usernumber = LOG_UUCP;
1240 else if (strncmp(case_username,
"AUDIT", 5) == 0) {
1241 *usernumber = LOG_AUDIT;
1245 else if (strncmp(case_username,
"CRON", 4) == 0) {
1246 *usernumber = LOG_CRON;
1249 else if (strncmp(case_username,
"LOCAL0", 6) == 0) {
1250 *usernumber = LOG_LOCAL0;
1252 else if (strncmp(case_username,
"LOCAL1", 6) == 0) {
1253 *usernumber = LOG_LOCAL1;
1255 else if (strncmp(case_username,
"LOCAL2", 6) == 0) {
1256 *usernumber = LOG_LOCAL2;
1258 else if (strncmp(case_username,
"LOCAL3", 6) == 0) {
1259 *usernumber = LOG_LOCAL3;
1261 else if (strncmp(case_username,
"LOCAL4", 6) == 0) {
1262 *usernumber = LOG_LOCAL4;
1264 else if (strncmp(case_username,
"LOCAL5", 6) == 0) {
1265 *usernumber = LOG_LOCAL5;
1267 else if (strncmp(case_username,
"LOCAL6", 6) == 0) {
1268 *usernumber = LOG_LOCAL6;
1270 else if (strncmp(case_username,
"LOCAL7", 6) == 0) {
1271 *usernumber = LOG_LOCAL7;
#define DEFAULT_LOG_FACILITY
int make_directory(DAEMONCONFIG *config, const char *path)
#define DEFAULT_LOG_FACILITY_STRING
int getPermsForDrop(DAEMONCONFIG *config)
void log_xml_error(void *ignore, const char *format,...)
void cmdlParse(DAEMONCONFIG *config, int *argc, char **argv)
int get_log_user(const char *username, int *usernumber)
void log_init(int facility, const char *program_name)
char * StrStrdup(const char *string)
int ReadConfig(DAEMONCONFIG *config, int verbose)
int write_data(DAEMONCONFIG *config, FILE *file, const void *data, size_t size)
int release_lite_lock(FILE *lock_fd)
void ksm_log_msg(const char *format)
void StrAppend(char **str1, const char *str2)
void log_xml_warn(void *ignore, const char *format,...)
int createPidDir(DAEMONCONFIG *config)
int get_lite_lock(char *lock_filename, FILE *lock_fd)
int writepid(DAEMONCONFIG *config)
void log_msg(DAEMONCONFIG *config, int priority, const char *format,...)
int DtXMLIntervalSeconds(const char *text, int *interval)
size_t StrToUpper(char *text)
void log_switch(int facility, const char *facility_name, const char *program_name, int verbose)