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;
649 config->
gid = getgid();
650 config->
uid = getuid();
657 if (*t !=
'.' || !isdigit(*++t)) {
658 log_msg(config, LOG_ERR,
"-u user or -u uid or -u uid.gid. exiting...");
661 config->
gid = strtol(t, &t, 10);
664 if ((pwd = getpwuid(config->
uid)) == NULL) {
665 log_msg(config, LOG_ERR,
"user id %u does not exist. exiting...", (
unsigned) config->
uid);
668 config->
gid = pwd->pw_gid;
674 if ((pwd = getpwnam(config->
username)) == NULL) {
675 log_msg(config, LOG_ERR,
"user '%s' does not exist. exiting...", config->
username);
678 config->
uid = pwd->pw_uid;
679 config->
gid = pwd->pw_gid;
688 fprintf(stdout,
"Will only process policy \"%s\", will only run once. Check the logs for results. \n", config->
policy);
714 xmlDocPtr doc = NULL;
715 xmlDocPtr rngdoc = NULL;
716 xmlXPathContextPtr xpathCtx = NULL;
717 xmlXPathObjectPtr xpathObj = NULL;
718 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
719 xmlRelaxNGValidCtxtPtr rngctx = NULL;
720 xmlRelaxNGPtr schema = NULL;
721 xmlChar *iv_expr = (
unsigned char*)
"//Configuration/Enforcer/Interval";
722 xmlChar *mk_expr = (
unsigned char*)
"//Configuration/Enforcer/ManualKeyGeneration";
723 xmlChar *rn_expr = (
unsigned char*)
"//Configuration/Enforcer/RolloverNotification";
724 xmlChar *ds_expr = (
unsigned char*)
"//Configuration/Enforcer/DelegationSignerSubmitCommand";
725 xmlChar *pid_expr = (
unsigned char*)
"//Configuration/Enforcer/PidFile";
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);
1126 xpathObj = xmlXPathEvalExpression(pid_expr, xpathCtx);
1127 if(xpathObj == NULL) {
1128 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", pid_expr);
1129 xmlXPathFreeContext(xpathCtx);
1134 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1137 config->
pidfile = (
char *)xmlXPathCastToString(xpathObj);
1139 log_msg(config, LOG_INFO,
"Pidfile set to: %s", config->
pidfile);
1144 xmlXPathFreeObject(xpathObj);
1169 if (lock_fd == NULL) {
1170 log_msg(NULL, LOG_ERR,
"%s could not be opened", lock_filename);
1174 memset(&fl, 0,
sizeof(
struct flock));
1175 fl.l_type = F_WRLCK;
1176 fl.l_whence = SEEK_SET;
1177 fl.l_pid = getpid();
1179 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1180 if (errno == EACCES || errno == EAGAIN) {
1181 log_msg(NULL, LOG_INFO,
"%s already locked, sleep", lock_filename);
1186 select(0, NULL, NULL, NULL, &tv);
1189 log_msg(NULL, LOG_INFO,
"couldn't get lock on %s, %s", lock_filename, strerror(errno));
1202 if (lock_fd == NULL) {
1206 memset(&fl, 0,
sizeof(
struct flock));
1207 fl.l_type = F_UNLCK;
1208 fl.l_whence = SEEK_SET;
1210 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1220 char* case_username = NULL;
1222 if (username == NULL) {
1232 if (strncmp(case_username,
"USER", 4) == 0) {
1233 *usernumber = LOG_USER;
1236 else if (strncmp(case_username,
"KERN", 4) == 0) {
1237 *usernumber = LOG_KERN;
1241 else if (strncmp(case_username,
"MAIL", 4) == 0) {
1242 *usernumber = LOG_MAIL;
1246 else if (strncmp(case_username,
"DAEMON", 6) == 0) {
1247 *usernumber = LOG_DAEMON;
1251 else if (strncmp(case_username,
"AUTH", 4) == 0) {
1252 *usernumber = LOG_AUTH;
1256 else if (strncmp(case_username,
"SYSLOG", 6) == 0) {
1257 *usernumber = LOG_SYSLOG;
1261 else if (strncmp(case_username,
"LPR", 3) == 0) {
1262 *usernumber = LOG_LPR;
1266 else if (strncmp(case_username,
"NEWS", 4) == 0) {
1267 *usernumber = LOG_NEWS;
1271 else if (strncmp(case_username,
"UUCP", 4) == 0) {
1272 *usernumber = LOG_UUCP;
1276 else if (strncmp(case_username,
"AUDIT", 5) == 0) {
1277 *usernumber = LOG_AUDIT;
1281 else if (strncmp(case_username,
"CRON", 4) == 0) {
1282 *usernumber = LOG_CRON;
1285 else if (strncmp(case_username,
"LOCAL0", 6) == 0) {
1286 *usernumber = LOG_LOCAL0;
1288 else if (strncmp(case_username,
"LOCAL1", 6) == 0) {
1289 *usernumber = LOG_LOCAL1;
1291 else if (strncmp(case_username,
"LOCAL2", 6) == 0) {
1292 *usernumber = LOG_LOCAL2;
1294 else if (strncmp(case_username,
"LOCAL3", 6) == 0) {
1295 *usernumber = LOG_LOCAL3;
1297 else if (strncmp(case_username,
"LOCAL4", 6) == 0) {
1298 *usernumber = LOG_LOCAL4;
1300 else if (strncmp(case_username,
"LOCAL5", 6) == 0) {
1301 *usernumber = LOG_LOCAL5;
1303 else if (strncmp(case_username,
"LOCAL6", 6) == 0) {
1304 *usernumber = LOG_LOCAL6;
1306 else if (strncmp(case_username,
"LOCAL7", 6) == 0) {
1307 *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)