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");
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:hdV?u:P:")) != -1) {
640 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;
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;
745 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
749 log_msg(config, LOG_INFO,
"Reading config \"%s\"", filename);
753 doc = xmlParseFile(filename);
756 file = fopen(filename,
"r");
758 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
760 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
768 log_msg(config, LOG_INFO,
"Reading config schema \"%s\"", rngfilename);
770 rngdoc = xmlParseFile(rngfilename);
771 if (rngdoc == NULL) {
773 file = fopen(rngfilename,
"r");
775 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
777 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
784 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
785 if (rngpctx == NULL) {
786 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
791 schema = xmlRelaxNGParse(rngpctx);
792 if (schema == NULL) {
793 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
798 rngctx = xmlRelaxNGNewValidCtxt(schema);
799 if (rngctx == NULL) {
800 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
804 xmlRelaxNGSetValidErrors(rngctx,
810 status = xmlRelaxNGValidateDoc(rngctx,doc);
812 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
815 xmlRelaxNGFreeValidCtxt(rngctx);
816 xmlRelaxNGFree(schema);
817 xmlRelaxNGFreeParserCtxt(rngpctx);
822 xpathCtx = xmlXPathNewContext(doc);
823 if(xpathCtx == NULL) {
824 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
830 xpathObj = xmlXPathEvalExpression(iv_expr, xpathCtx);
831 if(xpathObj == NULL) {
832 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", iv_expr);
833 xmlXPathFreeContext(xpathCtx);
838 temp_char = (
char *)xmlXPathCastToString(xpathObj);
841 log_msg(config, LOG_ERR,
"Error: unable to convert Interval %s to seconds, error: %i", temp_char, status);
845 else if (status == -1) {
846 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
850 log_msg(config, LOG_INFO,
"Communication Interval: %i", config->
interval);
853 xmlXPathFreeObject(xpathObj);
856 xpathObj = xmlXPathEvalExpression(mk_expr, xpathCtx);
857 if(xpathObj == NULL) {
858 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mk_expr);
859 xmlXPathFreeContext(xpathCtx);
864 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
872 xmlXPathFreeObject(xpathObj);
875 xpathObj = xmlXPathEvalExpression(rn_expr, xpathCtx);
876 if(xpathObj == NULL) {
877 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", rn_expr);
878 xmlXPathFreeContext(xpathCtx);
883 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
885 temp_char = (
char *)xmlXPathCastToString(xpathObj);
888 log_msg(config, LOG_ERR,
"Error: unable to convert RolloverNotification %s to seconds, error: %i", temp_char, status);
890 xmlXPathFreeObject(xpathObj);
893 else if (status == -1) {
894 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
906 xmlXPathFreeObject(xpathObj);
909 xpathObj = xmlXPathEvalExpression(ds_expr, xpathCtx);
910 if(xpathObj == NULL) {
911 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", ds_expr);
912 xmlXPathFreeContext(xpathCtx);
916 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
921 config->
DSSubmitCmd = (
char *)xmlXPathCastToString(xpathObj);
933 log_msg(config, LOG_INFO,
"Using command: %s to submit DS records", config->
DSSubmitCmd);
937 log_msg(config, LOG_INFO,
"No DS Submit command supplied");
941 xmlXPathFreeObject(xpathObj);
945 xpathObj = xmlXPathEvalExpression(litexpr, xpathCtx);
946 if(xpathObj == NULL) {
947 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", litexpr);
948 xmlXPathFreeContext(xpathCtx);
952 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
954 if (config->
schema != NULL) {
957 config->
schema = xmlXPathCastToString(xpathObj);
959 log_msg(config, LOG_INFO,
"SQLite database set to: %s", config->
schema);
962 xmlXPathFreeObject(xpathObj);
969 xpathObj = xmlXPathEvalExpression(mysql_host, xpathCtx);
970 if(xpathObj == NULL) {
971 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_host);
972 xmlXPathFreeContext(xpathCtx);
976 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
977 if (config->
host != NULL) {
980 config->
host = xmlXPathCastToString(xpathObj);
982 log_msg(config, LOG_INFO,
"MySQL database host set to: %s", config->
host);
985 xmlXPathFreeObject(xpathObj);
988 xpathObj = xmlXPathEvalExpression(mysql_port, xpathCtx);
989 if(xpathObj == NULL) {
990 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_port);
991 xmlXPathFreeContext(xpathCtx);
995 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
996 if (config->
port != NULL) {
999 config->
port = xmlXPathCastToString(xpathObj);
1001 log_msg(config, LOG_INFO,
"MySQL database port set to: %s", config->
port);
1004 xmlXPathFreeObject(xpathObj);
1007 xpathObj = xmlXPathEvalExpression(mysql_db, xpathCtx);
1008 if(xpathObj == NULL) {
1009 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_db);
1010 xmlXPathFreeContext(xpathCtx);
1014 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1015 if (config->
schema != NULL) {
1018 config->
schema = xmlXPathCastToString(xpathObj);
1020 log_msg(config, LOG_INFO,
"MySQL database schema set to: %s", config->
schema);
1025 xmlXPathFreeObject(xpathObj);
1028 xpathObj = xmlXPathEvalExpression(mysql_user, xpathCtx);
1029 if(xpathObj == NULL) {
1030 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_user);
1031 xmlXPathFreeContext(xpathCtx);
1035 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1036 if (config->
user != NULL) {
1039 config->
user = xmlXPathCastToString(xpathObj);
1041 log_msg(config, LOG_INFO,
"MySQL database user set to: %s", config->
user);
1046 xmlXPathFreeObject(xpathObj);
1049 xpathObj = xmlXPathEvalExpression(mysql_pass, xpathCtx);
1050 if(xpathObj == NULL) {
1051 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_pass);
1052 xmlXPathFreeContext(xpathCtx);
1061 config->
password = xmlXPathCastToString(xpathObj);
1063 log_msg(config, LOG_INFO,
"MySQL database password set");
1065 xmlXPathFreeObject(xpathObj);
1071 log_msg(config, LOG_ERR,
"Error: unable to find complete database connection expression in %s", filename);
1078 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");
1084 xpathObj = xmlXPathEvalExpression(log_user_expr, xpathCtx);
1085 if(xpathObj == NULL) {
1086 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", log_user_expr);
1087 xmlXPathFreeContext(xpathCtx);
1092 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1094 logFacilityName = (
char *)xmlXPathCastToString(xpathObj);
1098 log_msg(config, LOG_ERR,
"Error: unable to set log user: %s, error: %i", logFacilityName, status);
1100 xmlXPathFreeObject(xpathObj);
1101 xmlXPathFreeContext(xpathCtx);
1107 log_msg(config, LOG_INFO,
"Log User set to: %s", logFacilityName);
1115 log_msg(config, LOG_INFO,
"Using default log user: %s", logFacilityName);
1118 xmlXPathFreeObject(xpathObj);
1143 if (lock_fd == NULL) {
1144 log_msg(NULL, LOG_ERR,
"%s could not be opened", lock_filename);
1148 memset(&fl, 0,
sizeof(
struct flock));
1149 fl.l_type = F_WRLCK;
1150 fl.l_whence = SEEK_SET;
1151 fl.l_pid = getpid();
1153 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1154 if (errno == EACCES || errno == EAGAIN) {
1155 log_msg(NULL, LOG_INFO,
"%s already locked, sleep", lock_filename);
1160 select(0, NULL, NULL, NULL, &tv);
1163 log_msg(NULL, LOG_INFO,
"couldn't get lock on %s, %s", lock_filename, strerror(errno));
1176 if (lock_fd == NULL) {
1180 memset(&fl, 0,
sizeof(
struct flock));
1181 fl.l_type = F_UNLCK;
1182 fl.l_whence = SEEK_SET;
1184 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1194 char* case_username = NULL;
1196 if (username == NULL) {
1206 if (strncmp(case_username,
"USER", 4) == 0) {
1207 *usernumber = LOG_USER;
1210 else if (strncmp(case_username,
"KERN", 4) == 0) {
1211 *usernumber = LOG_KERN;
1215 else if (strncmp(case_username,
"MAIL", 4) == 0) {
1216 *usernumber = LOG_MAIL;
1220 else if (strncmp(case_username,
"DAEMON", 6) == 0) {
1221 *usernumber = LOG_DAEMON;
1225 else if (strncmp(case_username,
"AUTH", 4) == 0) {
1226 *usernumber = LOG_AUTH;
1230 else if (strncmp(case_username,
"SYSLOG", 6) == 0) {
1231 *usernumber = LOG_SYSLOG;
1235 else if (strncmp(case_username,
"LPR", 3) == 0) {
1236 *usernumber = LOG_LPR;
1240 else if (strncmp(case_username,
"NEWS", 4) == 0) {
1241 *usernumber = LOG_NEWS;
1245 else if (strncmp(case_username,
"UUCP", 4) == 0) {
1246 *usernumber = LOG_UUCP;
1250 else if (strncmp(case_username,
"AUDIT", 5) == 0) {
1251 *usernumber = LOG_AUDIT;
1255 else if (strncmp(case_username,
"CRON", 4) == 0) {
1256 *usernumber = LOG_CRON;
1259 else if (strncmp(case_username,
"LOCAL0", 6) == 0) {
1260 *usernumber = LOG_LOCAL0;
1262 else if (strncmp(case_username,
"LOCAL1", 6) == 0) {
1263 *usernumber = LOG_LOCAL1;
1265 else if (strncmp(case_username,
"LOCAL2", 6) == 0) {
1266 *usernumber = LOG_LOCAL2;
1268 else if (strncmp(case_username,
"LOCAL3", 6) == 0) {
1269 *usernumber = LOG_LOCAL3;
1271 else if (strncmp(case_username,
"LOCAL4", 6) == 0) {
1272 *usernumber = LOG_LOCAL4;
1274 else if (strncmp(case_username,
"LOCAL5", 6) == 0) {
1275 *usernumber = LOG_LOCAL5;
1277 else if (strncmp(case_username,
"LOCAL6", 6) == 0) {
1278 *usernumber = LOG_LOCAL6;
1280 else if (strncmp(case_username,
"LOCAL7", 6) == 0) {
1281 *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)