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>
82 #if defined(HAVE_SYSLOG_R) && defined(HAVE_OPENLOG_R) && defined(HAVE_CLOSELOG_R) && defined(HAVE_VSYSLOG_R)
83 struct syslog_data sdata = SYSLOG_DATA_INIT;
87 #undef HAVE_CLOSELOG_R
97 xmlDocPtr rngdoc = NULL;
98 xmlXPathContextPtr xpathCtx = NULL;
99 xmlXPathObjectPtr xpathObj = NULL;
100 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
101 xmlRelaxNGValidCtxtPtr rngctx = NULL;
102 xmlRelaxNGPtr schema = NULL;
103 xmlChar *user_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/User";
104 xmlChar *group_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/Group";
106 char* filename = NULL;
107 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
108 char* temp_char = NULL;
118 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
122 doc = xmlParseFile(filename);
125 file = fopen(filename,
"r");
127 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
129 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
136 rngdoc = xmlParseFile(rngfilename);
137 if (rngdoc == NULL) {
139 file = fopen(rngfilename,
"r");
141 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
143 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
150 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
151 if (rngpctx == NULL) {
152 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
157 schema = xmlRelaxNGParse(rngpctx);
158 if (schema == NULL) {
159 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
164 rngctx = xmlRelaxNGNewValidCtxt(schema);
165 if (rngctx == NULL) {
166 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
170 xmlRelaxNGSetValidErrors(rngctx,
176 status = xmlRelaxNGValidateDoc(rngctx,doc);
178 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
184 xpathCtx = xmlXPathNewContext(doc);
185 if(xpathCtx == NULL) {
186 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
192 xpathObj = xmlXPathEvalExpression(group_expr, xpathCtx);
193 if(xpathObj == NULL) {
194 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", group_expr);
195 xmlXPathFreeContext(xpathCtx);
199 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
200 temp_char = (
char*) xmlXPathCastToString(xpathObj);
203 xmlXPathFreeObject(xpathObj);
209 xpathObj = xmlXPathEvalExpression(user_expr, xpathCtx);
210 if(xpathObj == NULL) {
211 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", user_expr);
212 xmlXPathFreeContext(xpathCtx);
216 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
217 temp_char = (
char*) xmlXPathCastToString(xpathObj);
220 xmlXPathFreeObject(xpathObj);
228 if ((pwd = getpwnam(config->
username)) == NULL) {
230 syslog_r(LOG_ERR, &sdata,
"user '%s' does not exist. exiting...\n", config->
username);
232 syslog(LOG_ERR,
"user '%s' does not exist. exiting...\n", config->
username);
236 config->
uid = pwd->pw_uid;
242 if ((grp = getgrnam(config->
groupname)) == NULL) {
244 syslog_r(LOG_ERR, &sdata,
"group '%s' does not exist. exiting...\n", config->
groupname);
246 syslog(LOG_ERR,
"group '%s' does not exist. exiting...\n", config->
groupname);
250 config->
gid = grp->gr_gid;
255 xmlXPathFreeContext(xpathCtx);
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);
277 void log_switch(
int facility,
const char *facility_name,
const char *program_name,
int verbose)
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);
302 #ifdef HAVE_VSYSLOG_R
303 vsyslog_r(priority, &sdata, format, args);
305 vsyslog(priority, format, args);
316 if (strncmp(format,
"ERROR:", 6) == 0) {
318 syslog_r(LOG_ERR, &sdata,
"%s", format);
320 syslog(LOG_ERR,
"%s", format);
323 else if (strncmp(format,
"INFO:", 5) == 0) {
325 syslog_r(LOG_INFO, &sdata,
"%s", format);
327 syslog(LOG_INFO,
"%s", format);
330 else if (strncmp(format,
"WARNING:", 8) == 0) {
332 syslog_r(LOG_WARNING, &sdata,
"%s", format);
334 syslog(LOG_WARNING,
"%s", format);
337 else if (strncmp(format,
"DEBUG:", 6) == 0) {
339 syslog_r(LOG_DEBUG, &sdata,
"%s", format);
341 syslog(LOG_DEBUG,
"%s", format);
346 syslog_r(LOG_ERR, &sdata,
"%s", format);
348 syslog(LOG_ERR,
"%s", format);
362 va_start(args, format);
363 #ifdef HAVE_VSYSLOG_R
364 vsyslog_r(LOG_ERR, &sdata, format, args);
366 vsyslog(LOG_ERR, format, args);
380 va_start(args, format);
381 #ifdef HAVE_VSYSLOG_R
382 vsyslog_r(LOG_INFO, &sdata, format, args);
384 vsyslog(LOG_INFO, format, args);
390 usage(
const char* prog)
392 fprintf(stderr,
"Usage: %s [OPTION]...\n", prog);
393 fprintf(stderr,
"OpenDNSSEC Enforcer version %s\n\n", VERSION);
394 fprintf(stderr,
"Supported options:\n");
395 fprintf(stderr,
" -c <file> Use alternate conf.xml.\n");
396 fprintf(stderr,
" -d Debug.\n");
397 fprintf(stderr,
" -1 Run once, 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 stat(parent, &stat_ret);
591 if (!S_ISDIR(stat_ret.st_mode)) {
599 if (mkdir(path, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != 0) {
600 log_msg(NULL, LOG_ERR,
"cannot create directory %s: %s\n",
601 path, strerror(errno));
606 if (chown(path, config->
uid, config->
gid) == -1) {
607 log_msg(config, LOG_ERR,
"cannot chown(%u,%u) %s: %s",
608 (
unsigned) config->
uid, (
unsigned) config->
gid,
609 path, strerror(errno));
625 while ((c = getopt(*argc, argv,
"1c:hdV?u:P:")) != -1) {
634 config->
debug =
true;
643 config->
gid = getgid();
644 config->
uid = getuid();
651 if (*t !=
'.' || !isdigit(*++t)) {
652 log_msg(config, LOG_ERR,
"-u user or -u uid or -u uid.gid. exiting...");
655 config->
gid = strtol(t, &t, 10);
658 if ((pwd = getpwuid(config->
uid)) == NULL) {
659 log_msg(config, LOG_ERR,
"user id %u does not exist. exiting...", (
unsigned) config->
uid);
662 config->
gid = pwd->pw_gid;
668 if ((pwd = getpwnam(config->
username)) == NULL) {
669 log_msg(config, LOG_ERR,
"user '%s' does not exist. exiting...", config->
username);
672 config->
uid = pwd->pw_uid;
673 config->
gid = pwd->pw_gid;
703 xmlDocPtr doc = NULL;
704 xmlDocPtr rngdoc = NULL;
705 xmlXPathContextPtr xpathCtx = NULL;
706 xmlXPathObjectPtr xpathObj = NULL;
707 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
708 xmlRelaxNGValidCtxtPtr rngctx = NULL;
709 xmlRelaxNGPtr schema = NULL;
710 xmlChar *iv_expr = (
unsigned char*)
"//Configuration/Enforcer/Interval";
711 xmlChar *mk_expr = (
unsigned char*)
"//Configuration/Enforcer/ManualKeyGeneration";
712 xmlChar *rn_expr = (
unsigned char*)
"//Configuration/Enforcer/RolloverNotification";
713 xmlChar *ds_expr = (
unsigned char*)
"//Configuration/Enforcer/DelegationSignerSubmitCommand";
714 xmlChar *litexpr = (
unsigned char*)
"//Configuration/Enforcer/Datastore/SQLite";
715 xmlChar *mysql_host = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host";
716 xmlChar *mysql_port = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host/@port";
717 xmlChar *mysql_db = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Database";
718 xmlChar *mysql_user = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Username";
719 xmlChar *mysql_pass = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Password";
720 xmlChar *log_user_expr = (
unsigned char*)
"//Configuration/Common/Logging/Syslog/Facility";
723 char *logFacilityName;
727 char* filename = NULL;
728 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
730 char* temp_char = NULL;
738 filename =
StrStrdup(OPENDNSSEC_CONFIG_FILE);
742 log_msg(config, LOG_INFO,
"Reading config \"%s\"", filename);
746 doc = xmlParseFile(filename);
749 file = fopen(filename,
"r");
751 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", filename);
753 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", filename);
761 log_msg(config, LOG_INFO,
"Reading config schema \"%s\"", rngfilename);
763 rngdoc = xmlParseFile(rngfilename);
764 if (rngdoc == NULL) {
766 file = fopen(rngfilename,
"r");
768 log_msg(config, LOG_ERR,
"Error: unable to open file \"%s\"", rngfilename);
770 log_msg(config, LOG_ERR,
"Error: unable to parse file \"%s\"", rngfilename);
777 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
778 if (rngpctx == NULL) {
779 log_msg(config, LOG_ERR,
"Error: unable to create XML RelaxNGs parser context");
784 schema = xmlRelaxNGParse(rngpctx);
785 if (schema == NULL) {
786 log_msg(config, LOG_ERR,
"Error: unable to parse a schema definition resource");
791 rngctx = xmlRelaxNGNewValidCtxt(schema);
792 if (rngctx == NULL) {
793 log_msg(config, LOG_ERR,
"Error: unable to create RelaxNGs validation context based on the schema");
797 xmlRelaxNGSetValidErrors(rngctx,
803 status = xmlRelaxNGValidateDoc(rngctx,doc);
805 log_msg(config, LOG_ERR,
"Error validating file \"%s\"", filename);
808 xmlRelaxNGFreeValidCtxt(rngctx);
809 xmlRelaxNGFree(schema);
810 xmlRelaxNGFreeParserCtxt(rngpctx);
815 xpathCtx = xmlXPathNewContext(doc);
816 if(xpathCtx == NULL) {
817 log_msg(config, LOG_ERR,
"Error: unable to create new XPath context");
823 xpathObj = xmlXPathEvalExpression(iv_expr, xpathCtx);
824 if(xpathObj == NULL) {
825 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", iv_expr);
826 xmlXPathFreeContext(xpathCtx);
831 temp_char = (
char *)xmlXPathCastToString(xpathObj);
834 log_msg(config, LOG_ERR,
"Error: unable to convert Interval %s to seconds, error: %i", temp_char, status);
838 else if (status == -1) {
839 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
843 log_msg(config, LOG_INFO,
"Communication Interval: %i", config->
interval);
846 xmlXPathFreeObject(xpathObj);
849 xpathObj = xmlXPathEvalExpression(mk_expr, xpathCtx);
850 if(xpathObj == NULL) {
851 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mk_expr);
852 xmlXPathFreeContext(xpathCtx);
857 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
865 xmlXPathFreeObject(xpathObj);
868 xpathObj = xmlXPathEvalExpression(rn_expr, xpathCtx);
869 if(xpathObj == NULL) {
870 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", rn_expr);
871 xmlXPathFreeContext(xpathCtx);
876 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
878 temp_char = (
char *)xmlXPathCastToString(xpathObj);
881 log_msg(config, LOG_ERR,
"Error: unable to convert RolloverNotification %s to seconds, error: %i", temp_char, status);
885 else if (status == -1) {
886 log_msg(config, LOG_INFO,
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days", temp_char);
893 xmlXPathFreeObject(xpathObj);
901 xpathObj = xmlXPathEvalExpression(ds_expr, xpathCtx);
902 if(xpathObj == NULL) {
903 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", ds_expr);
904 xmlXPathFreeContext(xpathCtx);
908 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
913 config->
DSSubmitCmd = (
char *)xmlXPathCastToString(xpathObj);
916 log_msg(config, LOG_INFO,
"Using command: %s to submit DS records", config->
DSSubmitCmd);
918 xmlXPathFreeObject(xpathObj);
921 log_msg(config, LOG_INFO,
"No DS Submit command supplied");
928 xpathObj = xmlXPathEvalExpression(litexpr, xpathCtx);
929 if(xpathObj == NULL) {
930 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", litexpr);
931 xmlXPathFreeContext(xpathCtx);
935 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
937 if (config->
schema != NULL) {
940 config->
schema = xmlXPathCastToString(xpathObj);
942 log_msg(config, LOG_INFO,
"SQLite database set to: %s", config->
schema);
945 xmlXPathFreeObject(xpathObj);
952 xpathObj = xmlXPathEvalExpression(mysql_host, xpathCtx);
953 if(xpathObj == NULL) {
954 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_host);
955 xmlXPathFreeContext(xpathCtx);
959 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
960 if (config->
host != NULL) {
963 config->
host = xmlXPathCastToString(xpathObj);
965 log_msg(config, LOG_INFO,
"MySQL database host set to: %s", config->
host);
968 xmlXPathFreeObject(xpathObj);
971 xpathObj = xmlXPathEvalExpression(mysql_port, xpathCtx);
972 if(xpathObj == NULL) {
973 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_port);
974 xmlXPathFreeContext(xpathCtx);
978 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
979 if (config->
port != NULL) {
982 config->
port = xmlXPathCastToString(xpathObj);
984 log_msg(config, LOG_INFO,
"MySQL database port set to: %s", config->
port);
987 xmlXPathFreeObject(xpathObj);
990 xpathObj = xmlXPathEvalExpression(mysql_db, xpathCtx);
991 if(xpathObj == NULL) {
992 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_db);
993 xmlXPathFreeContext(xpathCtx);
997 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
998 if (config->
schema != NULL) {
1001 config->
schema = xmlXPathCastToString(xpathObj);
1003 log_msg(config, LOG_INFO,
"MySQL database schema set to: %s", config->
schema);
1008 xmlXPathFreeObject(xpathObj);
1011 xpathObj = xmlXPathEvalExpression(mysql_user, xpathCtx);
1012 if(xpathObj == NULL) {
1013 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_user);
1014 xmlXPathFreeContext(xpathCtx);
1018 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1019 if (config->
user != NULL) {
1022 config->
user = xmlXPathCastToString(xpathObj);
1024 log_msg(config, LOG_INFO,
"MySQL database user set to: %s", config->
user);
1029 xmlXPathFreeObject(xpathObj);
1032 xpathObj = xmlXPathEvalExpression(mysql_pass, xpathCtx);
1033 if(xpathObj == NULL) {
1034 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", mysql_pass);
1035 xmlXPathFreeContext(xpathCtx);
1044 config->
password = xmlXPathCastToString(xpathObj);
1046 log_msg(config, LOG_INFO,
"MySQL database password set");
1048 xmlXPathFreeObject(xpathObj);
1054 log_msg(config, LOG_ERR,
"Error: unable to find complete database connection expression in %s", filename);
1055 xmlXPathFreeContext(xpathCtx);
1062 log_msg(config, LOG_ERR,
"Error: database in config file %s does not match libksm", filename);
1063 xmlXPathFreeContext(xpathCtx);
1069 xpathObj = xmlXPathEvalExpression(log_user_expr, xpathCtx);
1070 if(xpathObj == NULL) {
1071 log_msg(config, LOG_ERR,
"Error: unable to evaluate xpath expression: %s", log_user_expr);
1072 xmlXPathFreeContext(xpathCtx);
1077 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
1079 logFacilityName = (
char *)xmlXPathCastToString(xpathObj);
1083 log_msg(config, LOG_ERR,
"Error: unable to set log user: %s, error: %i", logFacilityName, status);
1089 log_msg(config, LOG_INFO,
"Log User set to: %s", logFacilityName);
1097 log_msg(config, LOG_INFO,
"Using default log user: %s", logFacilityName);
1101 xmlXPathFreeObject(xpathObj);
1107 xmlXPathFreeContext(xpathCtx);
1127 if (lock_fd == NULL) {
1128 log_msg(NULL, LOG_ERR,
"%s could not be opened", lock_filename);
1132 memset(&fl, 0,
sizeof(
struct flock));
1133 fl.l_type = F_WRLCK;
1134 fl.l_whence = SEEK_SET;
1135 fl.l_pid = getpid();
1137 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1138 if (errno == EACCES || errno == EAGAIN) {
1139 log_msg(NULL, LOG_INFO,
"%s already locked, sleep", lock_filename);
1144 select(0, NULL, NULL, NULL, &tv);
1147 log_msg(NULL, LOG_INFO,
"couldn't get lock on %s, %s", lock_filename, strerror(errno));
1160 if (lock_fd == NULL) {
1164 memset(&fl, 0,
sizeof(
struct flock));
1165 fl.l_type = F_UNLCK;
1166 fl.l_whence = SEEK_SET;
1168 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
1178 char* case_username = NULL;
1180 if (username == NULL) {
1190 if (strncmp(case_username,
"USER", 4) == 0) {
1191 *usernumber = LOG_USER;
1194 else if (strncmp(case_username,
"KERN", 4) == 0) {
1195 *usernumber = LOG_KERN;
1199 else if (strncmp(case_username,
"MAIL", 4) == 0) {
1200 *usernumber = LOG_MAIL;
1204 else if (strncmp(case_username,
"DAEMON", 6) == 0) {
1205 *usernumber = LOG_DAEMON;
1209 else if (strncmp(case_username,
"AUTH", 4) == 0) {
1210 *usernumber = LOG_AUTH;
1214 else if (strncmp(case_username,
"SYSLOG", 6) == 0) {
1215 *usernumber = LOG_SYSLOG;
1219 else if (strncmp(case_username,
"LPR", 3) == 0) {
1220 *usernumber = LOG_LPR;
1224 else if (strncmp(case_username,
"NEWS", 4) == 0) {
1225 *usernumber = LOG_NEWS;
1229 else if (strncmp(case_username,
"UUCP", 4) == 0) {
1230 *usernumber = LOG_UUCP;
1234 else if (strncmp(case_username,
"AUDIT", 5) == 0) {
1235 *usernumber = LOG_AUDIT;
1239 else if (strncmp(case_username,
"CRON", 4) == 0) {
1240 *usernumber = LOG_CRON;
1243 else if (strncmp(case_username,
"LOCAL0", 6) == 0) {
1244 *usernumber = LOG_LOCAL0;
1246 else if (strncmp(case_username,
"LOCAL1", 6) == 0) {
1247 *usernumber = LOG_LOCAL1;
1249 else if (strncmp(case_username,
"LOCAL2", 6) == 0) {
1250 *usernumber = LOG_LOCAL2;
1252 else if (strncmp(case_username,
"LOCAL3", 6) == 0) {
1253 *usernumber = LOG_LOCAL3;
1255 else if (strncmp(case_username,
"LOCAL4", 6) == 0) {
1256 *usernumber = LOG_LOCAL4;
1258 else if (strncmp(case_username,
"LOCAL5", 6) == 0) {
1259 *usernumber = LOG_LOCAL5;
1261 else if (strncmp(case_username,
"LOCAL6", 6) == 0) {
1262 *usernumber = LOG_LOCAL6;
1264 else if (strncmp(case_username,
"LOCAL7", 6) == 0) {
1265 *usernumber = LOG_LOCAL7;