57 #include <sys/select.h>
58 #include <sys/types.h>
61 #include <libxml/tree.h>
62 #include <libxml/parser.h>
63 #include <libxml/xpath.h>
64 #include <libxml/xpathInternals.h>
65 #include <libxml/relaxng.h>
81 #if defined(HAVE_SYSLOG_R) && defined(HAVE_OPENLOG_R) && defined(HAVE_CLOSELOG_R) && defined(HAVE_VSYSLOG_R)
82 struct syslog_data sdata = SYSLOG_DATA_INIT;
86 #undef HAVE_CLOSELOG_R
96 xmlDocPtr rngdoc = NULL;
97 xmlXPathContextPtr xpathCtx = NULL;
98 xmlXPathObjectPtr xpathObj = NULL;
99 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
100 xmlRelaxNGValidCtxtPtr rngctx = NULL;
101 xmlRelaxNGPtr schema = NULL;
102 xmlChar *user_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/User";
103 xmlChar *group_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/Group";
105 char* filename = NULL;
106 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
107 char* temp_char = NULL;
117 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
121 doc = xmlParseFile(filename);
124 file = fopen(filename,
"r");
126 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
128 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
135 rngdoc = xmlParseFile(rngfilename);
136 if (rngdoc == NULL) {
138 file = fopen(rngfilename,
"r");
140 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
142 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
149 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
150 if (rngpctx == NULL) {
151 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
156 schema = xmlRelaxNGParse(rngpctx);
157 if (schema == NULL) {
158 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
163 rngctx = xmlRelaxNGNewValidCtxt(schema);
164 if (rngctx == NULL) {
165 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
169 xmlRelaxNGSetValidErrors(rngctx,
175 status = xmlRelaxNGValidateDoc(rngctx,doc);
177 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
183 xpathCtx = xmlXPathNewContext(doc);
184 if(xpathCtx == NULL) {
185 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
191 xpathObj = xmlXPathEvalExpression(group_expr, xpathCtx);
192 if(xpathObj == NULL) {
193 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", group_expr);
194 xmlXPathFreeContext(xpathCtx);
198 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
199 temp_char = (
char*) xmlXPathCastToString(xpathObj);
205 xmlXPathFreeObject(xpathObj);
208 xpathObj = xmlXPathEvalExpression(user_expr, xpathCtx);
209 if(xpathObj == NULL) {
210 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", user_expr);
211 xmlXPathFreeContext(xpathCtx);
215 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
216 temp_char = (
char*) xmlXPathCastToString(xpathObj);
222 xmlXPathFreeObject(xpathObj);
227 if ((pwd = getpwnam(config->
username)) == NULL) {
229 syslog_r(LOG_ERR, &sdata,
"user '%s' does not exist. exiting...\n", config->
username);
231 syslog(LOG_ERR,
"user '%s' does not exist. exiting...\n", config->
username);
235 config->
uid = pwd->pw_uid;
241 if ((grp = getgrnam(config->
groupname)) == NULL) {
243 syslog_r(LOG_ERR, &sdata,
"group '%s' does not exist. exiting...\n", config->
groupname);
245 syslog(LOG_ERR,
"group '%s' does not exist. exiting...\n", config->
groupname);
249 config->
gid = grp->gr_gid;
254 xmlRelaxNGFree(schema);
255 xmlRelaxNGFreeValidCtxt(rngctx);
256 xmlRelaxNGFreeParserCtxt(rngpctx);
265 void log_init(
int facility,
const char *program_name)
267 #ifdef HAVE_OPENLOG_R
268 openlog_r(program_name, 0, facility, &sdata);
270 openlog(program_name, 0, facility);
277 #ifdef HAVE_CLOSELOG_R
282 #ifdef HAVE_OPENLOG_R
283 openlog_r(program_name, 0, facility, &sdata);
285 openlog(program_name, 0, facility);
288 log_msg(NULL, LOG_INFO,
"Switched log facility to: %s", facility_name);
298 if (config && config->
debug) priority = LOG_ERR;
299 va_start(args, format);
301 #ifdef HAVE_VSYSLOG_R
302 vsyslog_r(priority, &sdata, format, args);
304 vsyslog(priority, format, args);
315 if (strncmp(format,
"ERROR:", 6) == 0) {
317 syslog_r(LOG_ERR, &sdata,
"%s", format);
319 syslog(LOG_ERR,
"%s", format);
322 else if (strncmp(format,
"INFO:", 5) == 0) {
324 syslog_r(LOG_INFO, &sdata,
"%s", format);
326 syslog(LOG_INFO,
"%s", format);
329 else if (strncmp(format,
"WARNING:", 8) == 0) {
331 syslog_r(LOG_WARNING, &sdata,
"%s", format);
333 syslog(LOG_WARNING,
"%s", format);
336 else if (strncmp(format,
"DEBUG:", 6) == 0) {
338 syslog_r(LOG_DEBUG, &sdata,
"%s", format);
340 syslog(LOG_DEBUG,
"%s", format);
345 syslog_r(LOG_ERR, &sdata,
"%s", format);
347 syslog(LOG_ERR,
"%s", format);
361 va_start(args, format);
362 #ifdef HAVE_VSYSLOG_R
363 vsyslog_r(LOG_ERR, &sdata, format, args);
365 vsyslog(LOG_ERR, format, args);
379 va_start(args, format);
380 #ifdef HAVE_VSYSLOG_R
381 vsyslog_r(LOG_INFO, &sdata, format, args);
383 vsyslog(LOG_INFO, format, args);
389 usage(
const char* prog)
391 fprintf(stderr,
"Usage: %s [OPTION]...\n", prog);
392 fprintf(stderr,
"OpenDNSSEC Enforcer version %s\n\n", VERSION);
393 fprintf(stderr,
"Supported options:\n");
394 fprintf(stderr,
" -c <file> Use alternate conf.xml.\n");
395 fprintf(stderr,
" -d Debug.\n");
396 fprintf(stderr,
" -1 Run once, then exit.\n");
397 fprintf(stderr,
" -p <policy> Run once processing only the specified policy, then exit.\n");
399 fprintf(stderr,
" -P <pidfile> Specify the PID file to write.\n");
401 fprintf(stderr,
" -V Print version.\n");
402 fprintf(stderr,
" -[?|h] This help.\n");
408 fprintf(stderr,
"%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
409 fprintf(stderr,
"Written by %s.\n\n",
AUTHOR_NAME);
410 fprintf(stderr,
"%s. This is free software.\n",
COPYRIGHT_STR);
411 fprintf(stderr,
"See source files for more license information\n");
423 result = fwrite(data, 1, size, file);
426 log_msg(config, LOG_ERR,
"write failed: %s", strerror(errno));
428 }
else if (result < size) {
429 log_msg(config, LOG_ERR,
"short write (disk full?)");
437 readpid(
const char *file)
445 if ((fd = open(file, O_RDONLY)) == -1) {
448 if (((l = read(fd, pidbuf,
sizeof(pidbuf)))) == -1) {
458 pid = strtol(pidbuf, &t, 10);
460 if (*t && *t !=
'\n') {
471 struct stat stat_ret;
476 if (stat(config->
pidfile, &stat_ret) != 0) {
478 if (errno != ENOENT) {
479 log_msg(config, LOG_ERR,
"cannot stat pidfile %s: %s",
480 config->
pidfile, strerror(errno));
484 if (S_ISREG(stat_ret.st_mode)) {
486 if ((oldpid = readpid(config->
pidfile)) == -1) {
488 if (errno != ENOENT) {
489 log_msg(config, LOG_ERR,
"cannot read pidfile %s: %s",
490 config->
pidfile, strerror(errno));
493 if (kill(oldpid, 0) == 0 || errno == EPERM) {
494 log_msg(config, LOG_ERR,
"pidfile %s already exists, "
495 "a process with pid %u is already running. "
496 "If no ods-enforcerd process is running, a previous "
497 "instance didn't shutdown cleanly, please remove this "
498 "file and try again.", config->
pidfile, oldpid);
501 log_msg(config, LOG_WARNING,
"pidfile %s already exists, "
502 "but no process with pid %u is running. "
503 "A previous instance didn't shutdown cleanly, this "
504 "pidfile is stale.", config->
pidfile, oldpid);
511 snprintf(pidbuf,
sizeof(pidbuf),
"%lu\n", (
unsigned long) config->
pid);
513 if ((fd = fopen(config->
pidfile,
"w")) == NULL ) {
517 if (!
write_data(config, fd, pidbuf, strlen(pidbuf))) {
523 if (chown(config->
pidfile, config->
uid, config->
gid) == -1) {
524 log_msg(config, LOG_ERR,
"cannot chown(%u,%u) %s: %s",
525 (
unsigned) config->
uid, (
unsigned) config->
gid,
526 config->
pidfile, strerror(errno));
538 char* directory = NULL;
540 struct stat stat_ret;
541 char *path = getenv(
"PWD");
551 slash = strrchr(directory,
'/');
555 if (stat(directory, &stat_ret) != 0) {
557 if (errno != ENOENT) {
558 log_msg(config, LOG_ERR,
"cannot stat directory %s: %s",
559 directory, strerror(errno));
564 if (S_ISDIR(stat_ret.st_mode)) {
582 struct stat stat_ret;
585 slash = strrchr(parent,
'/');
589 if (stat(parent, &stat_ret) != 0) {
590 if (errno != ENOENT) {
591 log_msg(NULL, LOG_ERR,
"cannot stat %s: %s\n",
592 parent, strerror(errno));
597 if (!S_ISDIR(stat_ret.st_mode)) {
604 if (mkdir(path, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != 0) {
605 log_msg(NULL, LOG_ERR,
"cannot create directory %s: %s\n",
606 path, strerror(errno));
611 if (chown(path, config->
uid, config->
gid) == -1) {
612 log_msg(config, LOG_ERR,
"cannot chown(%u,%u) %s: %s",
613 (
unsigned) config->
uid, (
unsigned) config->
gid,
614 path, strerror(errno));
630 while ((c = getopt(*argc, argv,
"1c:hdV?u:P:p:")) != -1) {
639 config->
debug =
true;
648 config->
gid = getgid();
649 config->
uid = getuid();
656 if (*t !=
'.' || !isdigit(*++t)) {
657 log_msg(config, LOG_ERR,
"-u user or -u uid or -u uid.gid. exiting...");
660 config->
gid = strtol(t, &t, 10);
663 if ((pwd = getpwuid(config->
uid)) == NULL) {
664 log_msg(config, LOG_ERR,
"user id %u does not exist. exiting...", (
unsigned) config->
uid);
667 config->
gid = pwd->pw_gid;
673 if ((pwd = getpwnam(config->
username)) == NULL) {
674 log_msg(config, LOG_ERR,
"user '%s' does not exist. exiting...", config->
username);
677 config->
uid = pwd->pw_uid;
678 config->
gid = pwd->pw_gid;
687 fprintf(stdout,
"Will only process policy \"%s\", will only run once. Check the logs for results. \n", config->
policy);
713 xmlDocPtr doc = NULL;
714 xmlDocPtr rngdoc = NULL;
715 xmlXPathContextPtr xpathCtx = NULL;
716 xmlXPathObjectPtr xpathObj = NULL;
717 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
718 xmlRelaxNGValidCtxtPtr rngctx = NULL;
719 xmlRelaxNGPtr schema = NULL;
720 xmlChar *iv_expr = (
unsigned char*)
"//Configuration/Enforcer/Interval";
721 xmlChar *mk_expr = (
unsigned char*)
"//Configuration/Enforcer/ManualKeyGeneration";
722 xmlChar *rn_expr = (
unsigned char*)
"//Configuration/Enforcer/RolloverNotification";
723 xmlChar *ds_expr = (
unsigned char*)
"//Configuration/Enforcer/DelegationSignerSubmitCommand";
724 xmlChar *litexpr = (
unsigned char*)
"//Configuration/Enforcer/Datastore/SQLite";
725 xmlChar *mysql_host = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host";
726 xmlChar *mysql_port = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host/@port";
727 xmlChar *mysql_db = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Database";
728 xmlChar *mysql_user = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Username";
729 xmlChar *mysql_pass = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Password";
730 xmlChar *log_user_expr = (
unsigned char*)
"//Configuration/Common/Logging/Syslog/Facility";
733 char *logFacilityName;
737 char* filename = NULL;
738 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
740 char* temp_char = NULL;
749 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
753 log_msg(config, LOG_INFO,
"Reading config \"%s\"", filename);
757 doc = xmlParseFile(filename);
760 file = fopen(filename,
"r");
762 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
764 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
772 log_msg(config, LOG_INFO,
"Reading config schema \"%s\"", rngfilename);
774 rngdoc = xmlParseFile(rngfilename);
775 if (rngdoc == NULL) {
777 file = fopen(rngfilename,
"r");
779 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
781 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
788 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
789 if (rngpctx == NULL) {
790 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
795 schema = xmlRelaxNGParse(rngpctx);
796 if (schema == NULL) {
797 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
802 rngctx = xmlRelaxNGNewValidCtxt(schema);
803 if (rngctx == NULL) {
804 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
808 xmlRelaxNGSetValidErrors(rngctx,
814 status = xmlRelaxNGValidateDoc(rngctx,doc);
816 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
819 xmlRelaxNGFreeValidCtxt(rngctx);
820 xmlRelaxNGFree(schema);
821 xmlRelaxNGFreeParserCtxt(rngpctx);
826 xpathCtx = xmlXPathNewContext(doc);
827 if(xpathCtx == NULL) {
828 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
834 xpathObj = xmlXPathEvalExpression(iv_expr, xpathCtx);
835 if(xpathObj == NULL) {
836 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", iv_expr);
837 xmlXPathFreeContext(xpathCtx);
842 temp_char = (
char *)xmlXPathCastToString(xpathObj);
845 log_msg(config, LOG_ERR,
"Error: unable to convert Interval %s to seconds, error: %i", temp_char, status);
849 else if (status == -1) {
850 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
854 log_msg(config, LOG_INFO,
"Communication Interval: %i", config->
interval);
857 xmlXPathFreeObject(xpathObj);
860 xpathObj = xmlXPathEvalExpression(mk_expr, xpathCtx);
861 if(xpathObj == NULL) {
862 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mk_expr);
863 xmlXPathFreeContext(xpathCtx);
868 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
876 xmlXPathFreeObject(xpathObj);
879 xpathObj = xmlXPathEvalExpression(rn_expr, xpathCtx);
880 if(xpathObj == NULL) {
881 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", rn_expr);
882 xmlXPathFreeContext(xpathCtx);
887 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
889 temp_char = (
char *)xmlXPathCastToString(xpathObj);
892 log_msg(config, LOG_ERR,
"Error: unable to convert RolloverNotification %s to seconds, error: %i", temp_char, status);
894 xmlXPathFreeObject(xpathObj);
897 else if (status == -1) {
898 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
910 xmlXPathFreeObject(xpathObj);
913 xpathObj = xmlXPathEvalExpression(ds_expr, xpathCtx);
914 if(xpathObj == NULL) {
915 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", ds_expr);
916 xmlXPathFreeContext(xpathCtx);
920 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
925 config->
DSSubmitCmd = (
char *)xmlXPathCastToString(xpathObj);
937 log_msg(config, LOG_INFO,
"Using command: %s to submit DS records", config->
DSSubmitCmd);
941 log_msg(config, LOG_INFO,
"No DS Submit command supplied");
945 xmlXPathFreeObject(xpathObj);
949 xpathObj = xmlXPathEvalExpression(litexpr, xpathCtx);
950 if(xpathObj == NULL) {
951 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", litexpr);
952 xmlXPathFreeContext(xpathCtx);
956 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
958 if (config->
schema != NULL) {
961 config->
schema = xmlXPathCastToString(xpathObj);
963 log_msg(config, LOG_INFO,
"SQLite database set to: %s", config->
schema);
966 xmlXPathFreeObject(xpathObj);
973 xpathObj = xmlXPathEvalExpression(mysql_host, xpathCtx);
974 if(xpathObj == NULL) {
975 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_host);
976 xmlXPathFreeContext(xpathCtx);
980 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
981 if (config->
host != NULL) {
984 config->
host = xmlXPathCastToString(xpathObj);
986 log_msg(config, LOG_INFO,
"MySQL database host set to: %s", config->
host);
989 xmlXPathFreeObject(xpathObj);
992 xpathObj = xmlXPathEvalExpression(mysql_port, xpathCtx);
993 if(xpathObj == NULL) {
994 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_port);
995 xmlXPathFreeContext(xpathCtx);
999 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1000 if (config->
port != NULL) {
1003 config->
port = xmlXPathCastToString(xpathObj);
1005 log_msg(config, LOG_INFO,
"MySQL database port set to: %s", config->
port);
1008 xmlXPathFreeObject(xpathObj);
1011 xpathObj = xmlXPathEvalExpression(mysql_db, xpathCtx);
1012 if(xpathObj == NULL) {
1013 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_db);
1014 xmlXPathFreeContext(xpathCtx);
1018 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1019 if (config->
schema != NULL) {
1022 config->
schema = xmlXPathCastToString(xpathObj);
1024 log_msg(config, LOG_INFO,
"MySQL database schema set to: %s", config->
schema);
1029 xmlXPathFreeObject(xpathObj);
1032 xpathObj = xmlXPathEvalExpression(mysql_user, xpathCtx);
1033 if(xpathObj == NULL) {
1034 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_user);
1035 xmlXPathFreeContext(xpathCtx);
1039 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1040 if (config->
user != NULL) {
1043 config->
user = xmlXPathCastToString(xpathObj);
1045 log_msg(config, LOG_INFO,
"MySQL database user set to: %s", config->
user);
1050 xmlXPathFreeObject(xpathObj);
1053 xpathObj = xmlXPathEvalExpression(mysql_pass, xpathCtx);
1054 if(xpathObj == NULL) {
1055 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_pass);
1056 xmlXPathFreeContext(xpathCtx);
1065 config->
password = xmlXPathCastToString(xpathObj);
1067 log_msg(config, LOG_INFO,
"MySQL database password set");
1069 xmlXPathFreeObject(xpathObj);
1075 log_msg(config, LOG_ERR,
"Error: unable to find complete database connection expression in %s", filename);
1082 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");
1088 xpathObj = xmlXPathEvalExpression(log_user_expr, xpathCtx);
1089 if(xpathObj == NULL) {
1090 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", log_user_expr);
1091 xmlXPathFreeContext(xpathCtx);
1096 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1098 logFacilityName = (
char *)xmlXPathCastToString(xpathObj);
1102 log_msg(config, LOG_ERR,
"Error: unable to set log user: %s, error: %i", logFacilityName, status);
1104 xmlXPathFreeObject(xpathObj);
1105 xmlXPathFreeContext(xpathCtx);
1111 log_msg(config, LOG_INFO,
"Log User set to: %s", logFacilityName);
1119 log_msg(config, LOG_INFO,
"Using default log user: %s", logFacilityName);
1122 xmlXPathFreeObject(xpathObj);
1147 if (lock_fd == NULL) {
1148 log_msg(NULL, LOG_ERR,
"%s could not be opened", lock_filename);
1152 memset(&fl, 0,
sizeof(
struct flock));
1153 fl.l_type = F_WRLCK;
1154 fl.l_whence = SEEK_SET;
1155 fl.l_pid = getpid();
1157 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1158 if (errno == EACCES || errno == EAGAIN) {
1159 log_msg(NULL, LOG_INFO,
"%s already locked, sleep", lock_filename);
1164 select(0, NULL, NULL, NULL, &tv);
1167 log_msg(NULL, LOG_INFO,
"couldn't get lock on %s, %s", lock_filename, strerror(errno));
1180 if (lock_fd == NULL) {
1184 memset(&fl, 0,
sizeof(
struct flock));
1185 fl.l_type = F_UNLCK;
1186 fl.l_whence = SEEK_SET;
1188 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1198 char* case_username = NULL;
1200 if (username == NULL) {
1210 if (strncmp(case_username,
"USER", 4) == 0) {
1211 *usernumber = LOG_USER;
1214 else if (strncmp(case_username,
"KERN", 4) == 0) {
1215 *usernumber = LOG_KERN;
1219 else if (strncmp(case_username,
"MAIL", 4) == 0) {
1220 *usernumber = LOG_MAIL;
1224 else if (strncmp(case_username,
"DAEMON", 6) == 0) {
1225 *usernumber = LOG_DAEMON;
1229 else if (strncmp(case_username,
"AUTH", 4) == 0) {
1230 *usernumber = LOG_AUTH;
1234 else if (strncmp(case_username,
"SYSLOG", 6) == 0) {
1235 *usernumber = LOG_SYSLOG;
1239 else if (strncmp(case_username,
"LPR", 3) == 0) {
1240 *usernumber = LOG_LPR;
1244 else if (strncmp(case_username,
"NEWS", 4) == 0) {
1245 *usernumber = LOG_NEWS;
1249 else if (strncmp(case_username,
"UUCP", 4) == 0) {
1250 *usernumber = LOG_UUCP;
1254 else if (strncmp(case_username,
"AUDIT", 5) == 0) {
1255 *usernumber = LOG_AUDIT;
1259 else if (strncmp(case_username,
"CRON", 4) == 0) {
1260 *usernumber = LOG_CRON;
1263 else if (strncmp(case_username,
"LOCAL0", 6) == 0) {
1264 *usernumber = LOG_LOCAL0;
1266 else if (strncmp(case_username,
"LOCAL1", 6) == 0) {
1267 *usernumber = LOG_LOCAL1;
1269 else if (strncmp(case_username,
"LOCAL2", 6) == 0) {
1270 *usernumber = LOG_LOCAL2;
1272 else if (strncmp(case_username,
"LOCAL3", 6) == 0) {
1273 *usernumber = LOG_LOCAL3;
1275 else if (strncmp(case_username,
"LOCAL4", 6) == 0) {
1276 *usernumber = LOG_LOCAL4;
1278 else if (strncmp(case_username,
"LOCAL5", 6) == 0) {
1279 *usernumber = LOG_LOCAL5;
1281 else if (strncmp(case_username,
"LOCAL6", 6) == 0) {
1282 *usernumber = LOG_LOCAL6;
1284 else if (strncmp(case_username,
"LOCAL7", 6) == 0) {
1285 *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)