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,
" -d no-daemonize.\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 if (stat(parent, &stat_ret) != 0) {
591 if (errno != ENOENT) {
592 log_msg(NULL, LOG_ERR,
"cannot stat %s: %s\n",
593 parent, strerror(errno));
598 if (!S_ISDIR(stat_ret.st_mode)) {
605 if (mkdir(path, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != 0) {
606 log_msg(NULL, LOG_ERR,
"cannot create directory %s: %s\n",
607 path, strerror(errno));
612 if (chown(path, config->
uid, config->
gid) == -1) {
613 log_msg(config, LOG_ERR,
"cannot chown(%u,%u) %s: %s",
614 (
unsigned) config->
uid, (
unsigned) config->
gid,
615 path, strerror(errno));
631 while ((c = getopt(*argc, argv,
"1c:hdDV?u:P:p:")) != -1) {
640 config->
debug =
true;
643 config->
fork =
false;
653 config->
gid = getgid();
654 config->
uid = getuid();
661 if (*t !=
'.' || !isdigit(*++t)) {
662 log_msg(config, LOG_ERR,
"-u user or -u uid or -u uid.gid. exiting...");
665 config->
gid = strtol(t, &t, 10);
668 if ((pwd = getpwuid(config->
uid)) == NULL) {
669 log_msg(config, LOG_ERR,
"user id %u does not exist. exiting...", (
unsigned) config->
uid);
672 config->
gid = pwd->pw_gid;
678 if ((pwd = getpwnam(config->
username)) == NULL) {
679 log_msg(config, LOG_ERR,
"user '%s' does not exist. exiting...", config->
username);
682 config->
uid = pwd->pw_uid;
683 config->
gid = pwd->pw_gid;
693 fprintf(stdout,
"Will only process policy \"%s\", will only run once. Check the logs for results. \n", config->
policy);
719 xmlDocPtr doc = NULL;
720 xmlDocPtr rngdoc = NULL;
721 xmlXPathContextPtr xpathCtx = NULL;
722 xmlXPathObjectPtr xpathObj = NULL;
723 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
724 xmlRelaxNGValidCtxtPtr rngctx = NULL;
725 xmlRelaxNGPtr schema = NULL;
726 xmlChar *iv_expr = (
unsigned char*)
"//Configuration/Enforcer/Interval";
727 xmlChar *mk_expr = (
unsigned char*)
"//Configuration/Enforcer/ManualKeyGeneration";
728 xmlChar *rn_expr = (
unsigned char*)
"//Configuration/Enforcer/RolloverNotification";
729 xmlChar *ds_expr = (
unsigned char*)
"//Configuration/Enforcer/DelegationSignerSubmitCommand";
730 xmlChar *pid_expr = (
unsigned char*)
"//Configuration/Enforcer/PidFile";
731 xmlChar *litexpr = (
unsigned char*)
"//Configuration/Enforcer/Datastore/SQLite";
732 xmlChar *mysql_host = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host";
733 xmlChar *mysql_port = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host/@port";
734 xmlChar *mysql_db = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Database";
735 xmlChar *mysql_user = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Username";
736 xmlChar *mysql_pass = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Password";
737 xmlChar *log_user_expr = (
unsigned char*)
"//Configuration/Common/Logging/Syslog/Facility";
740 char *logFacilityName;
744 char* filename = NULL;
745 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
747 char* temp_char = NULL;
756 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
760 log_msg(config, LOG_INFO,
"Reading config \"%s\"", filename);
764 doc = xmlParseFile(filename);
767 file = fopen(filename,
"r");
769 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
771 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
779 log_msg(config, LOG_INFO,
"Reading config schema \"%s\"", rngfilename);
781 rngdoc = xmlParseFile(rngfilename);
782 if (rngdoc == NULL) {
784 file = fopen(rngfilename,
"r");
786 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
788 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
795 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
796 if (rngpctx == NULL) {
797 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
802 schema = xmlRelaxNGParse(rngpctx);
803 if (schema == NULL) {
804 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
809 rngctx = xmlRelaxNGNewValidCtxt(schema);
810 if (rngctx == NULL) {
811 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
815 xmlRelaxNGSetValidErrors(rngctx,
821 status = xmlRelaxNGValidateDoc(rngctx,doc);
823 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
826 xmlRelaxNGFreeValidCtxt(rngctx);
827 xmlRelaxNGFree(schema);
828 xmlRelaxNGFreeParserCtxt(rngpctx);
833 xpathCtx = xmlXPathNewContext(doc);
834 if(xpathCtx == NULL) {
835 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
841 xpathObj = xmlXPathEvalExpression(iv_expr, xpathCtx);
842 if(xpathObj == NULL) {
843 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", iv_expr);
844 xmlXPathFreeContext(xpathCtx);
849 temp_char = (
char *)xmlXPathCastToString(xpathObj);
852 log_msg(config, LOG_ERR,
"Error: unable to convert Interval %s to seconds, error: %i", temp_char, status);
856 else if (status == -1) {
857 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
861 log_msg(config, LOG_INFO,
"Communication Interval: %i", config->
interval);
864 xmlXPathFreeObject(xpathObj);
867 xpathObj = xmlXPathEvalExpression(mk_expr, xpathCtx);
868 if(xpathObj == NULL) {
869 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mk_expr);
870 xmlXPathFreeContext(xpathCtx);
875 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
883 xmlXPathFreeObject(xpathObj);
886 xpathObj = xmlXPathEvalExpression(rn_expr, xpathCtx);
887 if(xpathObj == NULL) {
888 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", rn_expr);
889 xmlXPathFreeContext(xpathCtx);
894 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
896 temp_char = (
char *)xmlXPathCastToString(xpathObj);
899 log_msg(config, LOG_ERR,
"Error: unable to convert RolloverNotification %s to seconds, error: %i", temp_char, status);
901 xmlXPathFreeObject(xpathObj);
904 else if (status == -1) {
905 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
917 xmlXPathFreeObject(xpathObj);
920 xpathObj = xmlXPathEvalExpression(ds_expr, xpathCtx);
921 if(xpathObj == NULL) {
922 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", ds_expr);
923 xmlXPathFreeContext(xpathCtx);
927 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
932 config->
DSSubmitCmd = (
char *)xmlXPathCastToString(xpathObj);
944 log_msg(config, LOG_INFO,
"Using command: %s to submit DS records", config->
DSSubmitCmd);
948 log_msg(config, LOG_INFO,
"No DS Submit command supplied");
952 xmlXPathFreeObject(xpathObj);
956 xpathObj = xmlXPathEvalExpression(litexpr, xpathCtx);
957 if(xpathObj == NULL) {
958 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", litexpr);
959 xmlXPathFreeContext(xpathCtx);
963 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
965 if (config->
schema != NULL) {
968 config->
schema = xmlXPathCastToString(xpathObj);
970 log_msg(config, LOG_INFO,
"SQLite database set to: %s", config->
schema);
973 xmlXPathFreeObject(xpathObj);
980 xpathObj = xmlXPathEvalExpression(mysql_host, xpathCtx);
981 if(xpathObj == NULL) {
982 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_host);
983 xmlXPathFreeContext(xpathCtx);
987 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
988 if (config->
host != NULL) {
991 config->
host = xmlXPathCastToString(xpathObj);
993 log_msg(config, LOG_INFO,
"MySQL database host set to: %s", config->
host);
996 xmlXPathFreeObject(xpathObj);
999 xpathObj = xmlXPathEvalExpression(mysql_port, xpathCtx);
1000 if(xpathObj == NULL) {
1001 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_port);
1002 xmlXPathFreeContext(xpathCtx);
1006 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1007 if (config->
port != NULL) {
1010 config->
port = xmlXPathCastToString(xpathObj);
1012 log_msg(config, LOG_INFO,
"MySQL database port set to: %s", config->
port);
1015 xmlXPathFreeObject(xpathObj);
1018 xpathObj = xmlXPathEvalExpression(mysql_db, xpathCtx);
1019 if(xpathObj == NULL) {
1020 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_db);
1021 xmlXPathFreeContext(xpathCtx);
1025 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1026 if (config->
schema != NULL) {
1029 config->
schema = xmlXPathCastToString(xpathObj);
1031 log_msg(config, LOG_INFO,
"MySQL database schema set to: %s", config->
schema);
1036 xmlXPathFreeObject(xpathObj);
1039 xpathObj = xmlXPathEvalExpression(mysql_user, xpathCtx);
1040 if(xpathObj == NULL) {
1041 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_user);
1042 xmlXPathFreeContext(xpathCtx);
1046 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1047 if (config->
user != NULL) {
1050 config->
user = xmlXPathCastToString(xpathObj);
1052 log_msg(config, LOG_INFO,
"MySQL database user set to: %s", config->
user);
1057 xmlXPathFreeObject(xpathObj);
1060 xpathObj = xmlXPathEvalExpression(mysql_pass, xpathCtx);
1061 if(xpathObj == NULL) {
1062 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_pass);
1063 xmlXPathFreeContext(xpathCtx);
1072 config->
password = xmlXPathCastToString(xpathObj);
1074 log_msg(config, LOG_INFO,
"MySQL database password set");
1076 xmlXPathFreeObject(xpathObj);
1082 log_msg(config, LOG_ERR,
"Error: unable to find complete database connection expression in %s", filename);
1089 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");
1095 xpathObj = xmlXPathEvalExpression(log_user_expr, xpathCtx);
1096 if(xpathObj == NULL) {
1097 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", log_user_expr);
1098 xmlXPathFreeContext(xpathCtx);
1103 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1105 logFacilityName = (
char *)xmlXPathCastToString(xpathObj);
1109 log_msg(config, LOG_ERR,
"Error: unable to set log user: %s, error: %i", logFacilityName, status);
1111 xmlXPathFreeObject(xpathObj);
1112 xmlXPathFreeContext(xpathCtx);
1118 log_msg(config, LOG_INFO,
"Log User set to: %s", logFacilityName);
1126 log_msg(config, LOG_INFO,
"Using default log user: %s", logFacilityName);
1131 xpathObj = xmlXPathEvalExpression(pid_expr, xpathCtx);
1132 if(xpathObj == NULL) {
1133 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", pid_expr);
1134 xmlXPathFreeContext(xpathCtx);
1139 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1142 config->
pidfile = (
char *)xmlXPathCastToString(xpathObj);
1144 log_msg(config, LOG_INFO,
"Pidfile set to: %s", config->
pidfile);
1149 xmlXPathFreeObject(xpathObj);
1174 if (lock_fd == NULL) {
1175 log_msg(NULL, LOG_ERR,
"%s could not be opened", lock_filename);
1179 memset(&fl, 0,
sizeof(
struct flock));
1180 fl.l_type = F_WRLCK;
1181 fl.l_whence = SEEK_SET;
1182 fl.l_pid = getpid();
1184 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1185 if (errno == EACCES || errno == EAGAIN) {
1186 log_msg(NULL, LOG_INFO,
"%s already locked, sleep", lock_filename);
1191 select(0, NULL, NULL, NULL, &tv);
1194 log_msg(NULL, LOG_INFO,
"couldn't get lock on %s, %s", lock_filename, strerror(errno));
1207 if (lock_fd == NULL) {
1211 memset(&fl, 0,
sizeof(
struct flock));
1212 fl.l_type = F_UNLCK;
1213 fl.l_whence = SEEK_SET;
1215 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1225 char* case_username = NULL;
1227 if (username == NULL) {
1237 if (strncmp(case_username,
"USER", 4) == 0) {
1238 *usernumber = LOG_USER;
1241 else if (strncmp(case_username,
"KERN", 4) == 0) {
1242 *usernumber = LOG_KERN;
1246 else if (strncmp(case_username,
"MAIL", 4) == 0) {
1247 *usernumber = LOG_MAIL;
1251 else if (strncmp(case_username,
"DAEMON", 6) == 0) {
1252 *usernumber = LOG_DAEMON;
1256 else if (strncmp(case_username,
"AUTH", 4) == 0) {
1257 *usernumber = LOG_AUTH;
1261 else if (strncmp(case_username,
"SYSLOG", 6) == 0) {
1262 *usernumber = LOG_SYSLOG;
1266 else if (strncmp(case_username,
"LPR", 3) == 0) {
1267 *usernumber = LOG_LPR;
1271 else if (strncmp(case_username,
"NEWS", 4) == 0) {
1272 *usernumber = LOG_NEWS;
1276 else if (strncmp(case_username,
"UUCP", 4) == 0) {
1277 *usernumber = LOG_UUCP;
1281 else if (strncmp(case_username,
"AUDIT", 5) == 0) {
1282 *usernumber = LOG_AUDIT;
1286 else if (strncmp(case_username,
"CRON", 4) == 0) {
1287 *usernumber = LOG_CRON;
1290 else if (strncmp(case_username,
"LOCAL0", 6) == 0) {
1291 *usernumber = LOG_LOCAL0;
1293 else if (strncmp(case_username,
"LOCAL1", 6) == 0) {
1294 *usernumber = LOG_LOCAL1;
1296 else if (strncmp(case_username,
"LOCAL2", 6) == 0) {
1297 *usernumber = LOG_LOCAL2;
1299 else if (strncmp(case_username,
"LOCAL3", 6) == 0) {
1300 *usernumber = LOG_LOCAL3;
1302 else if (strncmp(case_username,
"LOCAL4", 6) == 0) {
1303 *usernumber = LOG_LOCAL4;
1305 else if (strncmp(case_username,
"LOCAL5", 6) == 0) {
1306 *usernumber = LOG_LOCAL5;
1308 else if (strncmp(case_username,
"LOCAL6", 6) == 0) {
1309 *usernumber = LOG_LOCAL6;
1311 else if (strncmp(case_username,
"LOCAL7", 6) == 0) {
1312 *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)