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>
83 #if defined(HAVE_SYSLOG_R) && defined(HAVE_OPENLOG_R) && defined(HAVE_CLOSELOG_R) && defined(HAVE_VSYSLOG_R)
84 struct syslog_data sdata = SYSLOG_DATA_INIT;
88 #undef HAVE_CLOSELOG_R
98 xmlDocPtr rngdoc = NULL;
99 xmlXPathContextPtr xpathCtx = NULL;
100 xmlXPathObjectPtr xpathObj = NULL;
101 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
102 xmlRelaxNGValidCtxtPtr rngctx = NULL;
103 xmlRelaxNGPtr schema = NULL;
104 xmlChar *user_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/User";
105 xmlChar *group_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/Group";
107 char* filename = NULL;
108 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
109 char* temp_char = NULL;
119 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
123 doc = xmlParseFile(filename);
126 file = fopen(filename,
"r");
128 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
130 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
137 rngdoc = xmlParseFile(rngfilename);
138 if (rngdoc == NULL) {
140 file = fopen(rngfilename,
"r");
142 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
144 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
151 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
152 if (rngpctx == NULL) {
153 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
158 schema = xmlRelaxNGParse(rngpctx);
159 if (schema == NULL) {
160 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
165 rngctx = xmlRelaxNGNewValidCtxt(schema);
166 if (rngctx == NULL) {
167 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
171 xmlRelaxNGSetValidErrors(rngctx,
177 status = xmlRelaxNGValidateDoc(rngctx,doc);
179 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
185 xpathCtx = xmlXPathNewContext(doc);
186 if(xpathCtx == NULL) {
187 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
193 xpathObj = xmlXPathEvalExpression(group_expr, xpathCtx);
194 if(xpathObj == NULL) {
195 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", group_expr);
196 xmlXPathFreeContext(xpathCtx);
200 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
201 temp_char = (
char*) xmlXPathCastToString(xpathObj);
207 xmlXPathFreeObject(xpathObj);
210 xpathObj = xmlXPathEvalExpression(user_expr, xpathCtx);
211 if(xpathObj == NULL) {
212 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", user_expr);
213 xmlXPathFreeContext(xpathCtx);
217 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
218 temp_char = (
char*) xmlXPathCastToString(xpathObj);
224 xmlXPathFreeObject(xpathObj);
229 if ((pwd = getpwnam(config->
username)) == NULL) {
231 syslog_r(LOG_ERR, &sdata,
"user '%s' does not exist. exiting...\n", config->
username);
233 syslog(LOG_ERR,
"user '%s' does not exist. exiting...\n", config->
username);
237 config->
uid = pwd->pw_uid;
243 if ((grp = getgrnam(config->
groupname)) == NULL) {
245 syslog_r(LOG_ERR, &sdata,
"group '%s' does not exist. exiting...\n", config->
groupname);
247 syslog(LOG_ERR,
"group '%s' does not exist. exiting...\n", config->
groupname);
251 config->
gid = grp->gr_gid;
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);
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);
303 #ifdef HAVE_VSYSLOG_R
304 vsyslog_r(priority, &sdata, format, args);
306 vsyslog(priority, format, args);
317 if (strncmp(format,
"ERROR:", 6) == 0) {
319 syslog_r(LOG_ERR, &sdata,
"%s", format);
321 syslog(LOG_ERR,
"%s", format);
324 else if (strncmp(format,
"INFO:", 5) == 0) {
326 syslog_r(LOG_INFO, &sdata,
"%s", format);
328 syslog(LOG_INFO,
"%s", format);
331 else if (strncmp(format,
"WARNING:", 8) == 0) {
333 syslog_r(LOG_WARNING, &sdata,
"%s", format);
335 syslog(LOG_WARNING,
"%s", format);
338 else if (strncmp(format,
"DEBUG:", 6) == 0) {
340 syslog_r(LOG_DEBUG, &sdata,
"%s", format);
342 syslog(LOG_DEBUG,
"%s", format);
347 syslog_r(LOG_ERR, &sdata,
"%s", format);
349 syslog(LOG_ERR,
"%s", format);
363 va_start(args, format);
364 #ifdef HAVE_VSYSLOG_R
365 vsyslog_r(LOG_ERR, &sdata, format, args);
367 vsyslog(LOG_ERR, format, args);
381 va_start(args, format);
382 #ifdef HAVE_VSYSLOG_R
383 vsyslog_r(LOG_INFO, &sdata, format, args);
385 vsyslog(LOG_INFO, format, args);
391 usage(
const char* prog)
393 fprintf(stderr,
"Usage: %s [OPTION]...\n", prog);
394 fprintf(stderr,
"OpenDNSSEC Enforcer version %s\n\n", VERSION);
395 fprintf(stderr,
"Supported options:\n");
396 fprintf(stderr,
" -c <file> Use alternate conf.xml.\n");
397 fprintf(stderr,
" -d Debug.\n");
398 fprintf(stderr,
" -1 Run once, then exit.\n");
399 fprintf(stderr,
" -p <policy> Run once processing only the specified policy, then exit.\n");
401 fprintf(stderr,
" -P <pidfile> Specify the PID file to write.\n");
403 fprintf(stderr,
" -V Print version.\n");
404 fprintf(stderr,
" -[?|h] This help.\n");
410 fprintf(stderr,
"%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
411 fprintf(stderr,
"Written by %s.\n\n",
AUTHOR_NAME);
412 fprintf(stderr,
"%s. This is free software.\n",
COPYRIGHT_STR);
413 fprintf(stderr,
"See source files for more license information\n");
425 result = fwrite(data, 1, size, file);
428 log_msg(config, LOG_ERR,
"write failed: %s", strerror(errno));
430 }
else if (result < size) {
431 log_msg(config, LOG_ERR,
"short write (disk full?)");
439 readpid(
const char *file)
447 if ((fd = open(file, O_RDONLY)) == -1) {
450 if (((l = read(fd, pidbuf,
sizeof(pidbuf)))) == -1) {
460 pid = strtol(pidbuf, &t, 10);
462 if (*t && *t !=
'\n') {
473 struct stat stat_ret;
478 if (stat(config->
pidfile, &stat_ret) != 0) {
480 if (errno != ENOENT) {
481 log_msg(config, LOG_ERR,
"cannot stat pidfile %s: %s",
482 config->
pidfile, strerror(errno));
486 if (S_ISREG(stat_ret.st_mode)) {
488 if ((oldpid = readpid(config->
pidfile)) == -1) {
490 if (errno != ENOENT) {
491 log_msg(config, LOG_ERR,
"cannot read pidfile %s: %s",
492 config->
pidfile, strerror(errno));
495 if (kill(oldpid, 0) == 0 || errno == EPERM) {
496 log_msg(config, LOG_ERR,
"pidfile %s already exists, "
497 "a process with pid %u is already running. "
498 "If no ods-enforcerd process is running, a previous "
499 "instance didn't shutdown cleanly, please remove this "
500 "file and try again.", config->
pidfile, oldpid);
503 log_msg(config, LOG_WARNING,
"pidfile %s already exists, "
504 "but no process with pid %u is running. "
505 "A previous instance didn't shutdown cleanly, this "
506 "pidfile is stale.", config->
pidfile, oldpid);
513 snprintf(pidbuf,
sizeof(pidbuf),
"%lu\n", (
unsigned long) config->
pid);
515 if ((fd = fopen(config->
pidfile,
"w")) == NULL ) {
519 if (!
write_data(config, fd, pidbuf, strlen(pidbuf))) {
525 if (chown(config->
pidfile, config->
uid, config->
gid) == -1) {
526 log_msg(config, LOG_ERR,
"cannot chown(%u,%u) %s: %s",
527 (
unsigned) config->
uid, (
unsigned) config->
gid,
528 config->
pidfile, strerror(errno));
540 char* directory = NULL;
542 struct stat stat_ret;
543 char *path = getenv(
"PWD");
553 slash = strrchr(directory,
'/');
557 if (stat(directory, &stat_ret) != 0) {
559 if (errno != ENOENT) {
560 log_msg(config, LOG_ERR,
"cannot stat directory %s: %s",
561 directory, strerror(errno));
566 if (S_ISDIR(stat_ret.st_mode)) {
584 struct stat stat_ret;
587 slash = strrchr(parent,
'/');
591 if (stat(parent, &stat_ret) != 0) {
592 if (errno != ENOENT) {
593 log_msg(NULL, LOG_ERR,
"cannot stat %s: %s\n",
594 parent, strerror(errno));
599 if (!S_ISDIR(stat_ret.st_mode)) {
606 if (mkdir(path, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != 0) {
607 log_msg(NULL, LOG_ERR,
"cannot create directory %s: %s\n",
608 path, strerror(errno));
613 if (chown(path, config->
uid, config->
gid) == -1) {
614 log_msg(config, LOG_ERR,
"cannot chown(%u,%u) %s: %s",
615 (
unsigned) config->
uid, (
unsigned) config->
gid,
616 path, strerror(errno));
632 while ((c = getopt(*argc, argv,
"1c:hdV?u:P:p:")) != -1) {
641 config->
debug =
true;
650 config->
gid = getgid();
651 config->
uid = getuid();
658 if (*t !=
'.' || !isdigit(*++t)) {
659 log_msg(config, LOG_ERR,
"-u user or -u uid or -u uid.gid. exiting...");
662 config->
gid = strtol(t, &t, 10);
665 if ((pwd = getpwuid(config->
uid)) == NULL) {
666 log_msg(config, LOG_ERR,
"user id %u does not exist. exiting...", (
unsigned) config->
uid);
669 config->
gid = pwd->pw_gid;
675 if ((pwd = getpwnam(config->
username)) == NULL) {
676 log_msg(config, LOG_ERR,
"user '%s' does not exist. exiting...", config->
username);
679 config->
uid = pwd->pw_uid;
680 config->
gid = pwd->pw_gid;
689 fprintf(stdout,
"Will only process policy \"%s\", will only run once. Check the logs for results. \n", config->
policy);
715 xmlDocPtr doc = NULL;
716 xmlDocPtr rngdoc = NULL;
717 xmlXPathContextPtr xpathCtx = NULL;
718 xmlXPathObjectPtr xpathObj = NULL;
719 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
720 xmlRelaxNGValidCtxtPtr rngctx = NULL;
721 xmlRelaxNGPtr schema = NULL;
722 xmlChar *iv_expr = (
unsigned char*)
"//Configuration/Enforcer/Interval";
723 xmlChar *mk_expr = (
unsigned char*)
"//Configuration/Enforcer/ManualKeyGeneration";
724 xmlChar *rn_expr = (
unsigned char*)
"//Configuration/Enforcer/RolloverNotification";
725 xmlChar *ds_expr = (
unsigned char*)
"//Configuration/Enforcer/DelegationSignerSubmitCommand";
726 xmlChar *litexpr = (
unsigned char*)
"//Configuration/Enforcer/Datastore/SQLite";
727 xmlChar *mysql_host = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host";
728 xmlChar *mysql_port = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host/@port";
729 xmlChar *mysql_db = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Database";
730 xmlChar *mysql_user = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Username";
731 xmlChar *mysql_pass = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Password";
732 xmlChar *log_user_expr = (
unsigned char*)
"//Configuration/Common/Logging/Syslog/Facility";
735 char *logFacilityName;
739 char* filename = NULL;
740 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
742 char* temp_char = NULL;
751 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
755 log_msg(config, LOG_INFO,
"Reading config \"%s\"", filename);
759 doc = xmlParseFile(filename);
762 file = fopen(filename,
"r");
764 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
766 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
774 log_msg(config, LOG_INFO,
"Reading config schema \"%s\"", rngfilename);
776 rngdoc = xmlParseFile(rngfilename);
777 if (rngdoc == NULL) {
779 file = fopen(rngfilename,
"r");
781 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
783 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
790 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
791 if (rngpctx == NULL) {
792 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
797 schema = xmlRelaxNGParse(rngpctx);
798 if (schema == NULL) {
799 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
804 rngctx = xmlRelaxNGNewValidCtxt(schema);
805 if (rngctx == NULL) {
806 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
810 xmlRelaxNGSetValidErrors(rngctx,
816 status = xmlRelaxNGValidateDoc(rngctx,doc);
818 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
821 xmlRelaxNGFreeValidCtxt(rngctx);
822 xmlRelaxNGFree(schema);
823 xmlRelaxNGFreeParserCtxt(rngpctx);
828 xpathCtx = xmlXPathNewContext(doc);
829 if(xpathCtx == NULL) {
830 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
836 xpathObj = xmlXPathEvalExpression(iv_expr, xpathCtx);
837 if(xpathObj == NULL) {
838 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", iv_expr);
839 xmlXPathFreeContext(xpathCtx);
844 temp_char = (
char *)xmlXPathCastToString(xpathObj);
847 log_msg(config, LOG_ERR,
"Error: unable to convert Interval %s to seconds, error: %i", temp_char, status);
851 else if (status == -1) {
852 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
856 log_msg(config, LOG_INFO,
"Communication Interval: %i", config->
interval);
859 xmlXPathFreeObject(xpathObj);
862 xpathObj = xmlXPathEvalExpression(mk_expr, xpathCtx);
863 if(xpathObj == NULL) {
864 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mk_expr);
865 xmlXPathFreeContext(xpathCtx);
870 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
878 xmlXPathFreeObject(xpathObj);
881 xpathObj = xmlXPathEvalExpression(rn_expr, xpathCtx);
882 if(xpathObj == NULL) {
883 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", rn_expr);
884 xmlXPathFreeContext(xpathCtx);
889 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
891 temp_char = (
char *)xmlXPathCastToString(xpathObj);
894 log_msg(config, LOG_ERR,
"Error: unable to convert RolloverNotification %s to seconds, error: %i", temp_char, status);
896 xmlXPathFreeObject(xpathObj);
899 else if (status == -1) {
900 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
912 xmlXPathFreeObject(xpathObj);
915 xpathObj = xmlXPathEvalExpression(ds_expr, xpathCtx);
916 if(xpathObj == NULL) {
917 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", ds_expr);
918 xmlXPathFreeContext(xpathCtx);
922 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
927 config->
DSSubmitCmd = (
char *)xmlXPathCastToString(xpathObj);
939 log_msg(config, LOG_INFO,
"Using command: %s to submit DS records", config->
DSSubmitCmd);
943 log_msg(config, LOG_INFO,
"No DS Submit command supplied");
947 xmlXPathFreeObject(xpathObj);
951 xpathObj = xmlXPathEvalExpression(litexpr, xpathCtx);
952 if(xpathObj == NULL) {
953 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", litexpr);
954 xmlXPathFreeContext(xpathCtx);
958 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
960 if (config->
schema != NULL) {
963 config->
schema = xmlXPathCastToString(xpathObj);
965 log_msg(config, LOG_INFO,
"SQLite database set to: %s", config->
schema);
968 xmlXPathFreeObject(xpathObj);
975 xpathObj = xmlXPathEvalExpression(mysql_host, xpathCtx);
976 if(xpathObj == NULL) {
977 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_host);
978 xmlXPathFreeContext(xpathCtx);
982 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
983 if (config->
host != NULL) {
986 config->
host = xmlXPathCastToString(xpathObj);
988 log_msg(config, LOG_INFO,
"MySQL database host set to: %s", config->
host);
991 xmlXPathFreeObject(xpathObj);
994 xpathObj = xmlXPathEvalExpression(mysql_port, xpathCtx);
995 if(xpathObj == NULL) {
996 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_port);
997 xmlXPathFreeContext(xpathCtx);
1001 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1002 if (config->
port != NULL) {
1005 config->
port = xmlXPathCastToString(xpathObj);
1007 log_msg(config, LOG_INFO,
"MySQL database port set to: %s", config->
port);
1010 xmlXPathFreeObject(xpathObj);
1013 xpathObj = xmlXPathEvalExpression(mysql_db, xpathCtx);
1014 if(xpathObj == NULL) {
1015 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_db);
1016 xmlXPathFreeContext(xpathCtx);
1020 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1021 if (config->
schema != NULL) {
1024 config->
schema = xmlXPathCastToString(xpathObj);
1026 log_msg(config, LOG_INFO,
"MySQL database schema set to: %s", config->
schema);
1031 xmlXPathFreeObject(xpathObj);
1034 xpathObj = xmlXPathEvalExpression(mysql_user, xpathCtx);
1035 if(xpathObj == NULL) {
1036 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_user);
1037 xmlXPathFreeContext(xpathCtx);
1041 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1042 if (config->
user != NULL) {
1045 config->
user = xmlXPathCastToString(xpathObj);
1047 log_msg(config, LOG_INFO,
"MySQL database user set to: %s", config->
user);
1052 xmlXPathFreeObject(xpathObj);
1055 xpathObj = xmlXPathEvalExpression(mysql_pass, xpathCtx);
1056 if(xpathObj == NULL) {
1057 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_pass);
1058 xmlXPathFreeContext(xpathCtx);
1067 config->
password = xmlXPathCastToString(xpathObj);
1069 log_msg(config, LOG_INFO,
"MySQL database password set");
1071 xmlXPathFreeObject(xpathObj);
1077 log_msg(config, LOG_ERR,
"Error: unable to find complete database connection expression in %s", filename);
1084 log_msg(config, LOG_ERR,
"Error: Config file %s specifies database type %s but system is compiled to use %s", filename, (db_found==1) ?
"MySQL" :
"sqlite3", (db_found==2) ?
"MySQL" :
"sqlite3");
1090 xpathObj = xmlXPathEvalExpression(log_user_expr, xpathCtx);
1091 if(xpathObj == NULL) {
1092 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", log_user_expr);
1093 xmlXPathFreeContext(xpathCtx);
1098 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1100 logFacilityName = (
char *)xmlXPathCastToString(xpathObj);
1104 log_msg(config, LOG_ERR,
"Error: unable to set log user: %s, error: %i", logFacilityName, status);
1106 xmlXPathFreeObject(xpathObj);
1107 xmlXPathFreeContext(xpathCtx);
1113 log_msg(config, LOG_INFO,
"Log User set to: %s", logFacilityName);
1121 log_msg(config, LOG_INFO,
"Using default log user: %s", logFacilityName);
1124 xmlXPathFreeObject(xpathObj);
1149 if (lock_fd == NULL) {
1150 log_msg(NULL, LOG_ERR,
"%s could not be opened", lock_filename);
1154 memset(&fl, 0,
sizeof(
struct flock));
1155 fl.l_type = F_WRLCK;
1156 fl.l_whence = SEEK_SET;
1157 fl.l_pid = getpid();
1159 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1160 if (errno == EACCES || errno == EAGAIN) {
1161 log_msg(NULL, LOG_INFO,
"%s already locked, sleep", lock_filename);
1166 select(0, NULL, NULL, NULL, &tv);
1169 log_msg(NULL, LOG_INFO,
"couldn't get lock on %s, %s", lock_filename, strerror(errno));
1182 if (lock_fd == NULL) {
1186 memset(&fl, 0,
sizeof(
struct flock));
1187 fl.l_type = F_UNLCK;
1188 fl.l_whence = SEEK_SET;
1190 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1200 char* case_username = NULL;
1202 if (username == NULL) {
1212 if (strncmp(case_username,
"USER", 4) == 0) {
1213 *usernumber = LOG_USER;
1216 else if (strncmp(case_username,
"KERN", 4) == 0) {
1217 *usernumber = LOG_KERN;
1221 else if (strncmp(case_username,
"MAIL", 4) == 0) {
1222 *usernumber = LOG_MAIL;
1226 else if (strncmp(case_username,
"DAEMON", 6) == 0) {
1227 *usernumber = LOG_DAEMON;
1231 else if (strncmp(case_username,
"AUTH", 4) == 0) {
1232 *usernumber = LOG_AUTH;
1236 else if (strncmp(case_username,
"SYSLOG", 6) == 0) {
1237 *usernumber = LOG_SYSLOG;
1241 else if (strncmp(case_username,
"LPR", 3) == 0) {
1242 *usernumber = LOG_LPR;
1246 else if (strncmp(case_username,
"NEWS", 4) == 0) {
1247 *usernumber = LOG_NEWS;
1251 else if (strncmp(case_username,
"UUCP", 4) == 0) {
1252 *usernumber = LOG_UUCP;
1256 else if (strncmp(case_username,
"AUDIT", 5) == 0) {
1257 *usernumber = LOG_AUDIT;
1261 else if (strncmp(case_username,
"CRON", 4) == 0) {
1262 *usernumber = LOG_CRON;
1265 else if (strncmp(case_username,
"LOCAL0", 6) == 0) {
1266 *usernumber = LOG_LOCAL0;
1268 else if (strncmp(case_username,
"LOCAL1", 6) == 0) {
1269 *usernumber = LOG_LOCAL1;
1271 else if (strncmp(case_username,
"LOCAL2", 6) == 0) {
1272 *usernumber = LOG_LOCAL2;
1274 else if (strncmp(case_username,
"LOCAL3", 6) == 0) {
1275 *usernumber = LOG_LOCAL3;
1277 else if (strncmp(case_username,
"LOCAL4", 6) == 0) {
1278 *usernumber = LOG_LOCAL4;
1280 else if (strncmp(case_username,
"LOCAL5", 6) == 0) {
1281 *usernumber = LOG_LOCAL5;
1283 else if (strncmp(case_username,
"LOCAL6", 6) == 0) {
1284 *usernumber = LOG_LOCAL6;
1286 else if (strncmp(case_username,
"LOCAL7", 6) == 0) {
1287 *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)