/** * Returns the backlog time-offset for making requests of an upstream LDM. * * @return The backlog time-offset, in seconds, for making requests of an * upstream LDM. */ unsigned getTimeOffset(void) { static unsigned timeOffset; static int isSet = 0; if (!isSet) { int status = reg_getUint(REG_TIME_OFFSET, &timeOffset); if (status) { timeOffset = 3600; LOG_ADD1("Using default value: %u seconds", timeOffset); if (status == ENOENT) { log_log(LOG_INFO); isSet = 1; } else { log_log(LOG_ERR); } } else { isSet = 1; } } return timeOffset; }
/* write the current process id to the specified file */ static void create_pidfile(const char *filename) { int fd; char buffer[20]; if (filename != NULL) { mkdirname(filename); if ((fd = open(filename, O_RDWR | O_CREAT, 0644)) < 0) { log_log(LOG_ERR, "cannot create pid file (%s): %s", filename, strerror(errno)); exit(EXIT_FAILURE); } if (lockf(fd, F_TLOCK, 0) < 0) { log_log(LOG_ERR, "cannot lock pid file (%s): %s", filename, strerror(errno)); exit(EXIT_FAILURE); } if (ftruncate(fd, 0) < 0) { log_log(LOG_ERR, "cannot truncate pid file (%s): %s", filename, strerror(errno)); exit(EXIT_FAILURE); } mysnprintf(buffer, sizeof(buffer), "%d\n", (int)getpid()); if (write(fd, buffer, strlen(buffer)) != (int)strlen(buffer)) { log_log(LOG_ERR, "error writing pid file (%s): %s", filename, strerror(errno)); exit(EXIT_FAILURE); } /* we keep the pidfile open so the lock remains valid */ } }
Edge getDeepBoxMove(UnscoredState * state, int turnTimeMillis) { Edge moveChoice; short numEdgesLeft = getNumFreeEdges(state); if (numEdgesLeft > 37) { log_log("Using always4never3 strategy...\n"); moveChoice = getMoveAlways4Never3(state); } else { log_log("Looking for urgent moves...\n"); SCGraph graph; unscoredStateToSCGraph(&graph, state); Edge urgentMoves[2]; short numUrgentMoves = getSuperGraphUrgentMoves(&graph, urgentMoves); freeAdjLists(&graph); if (numUrgentMoves == 1) { log_log("Found one: %d\n", urgentMoves[0]); moveChoice = urgentMoves[0]; } else { log_log("Didn't find one. Using alpha-beta strategy...\n"); moveChoice = getABMove(state, 7 + 10-(int)numEdgesLeft/3.0, false); } } // The graph representation knows nothing about the distinctions of corner edges. if (isEdgeTaken(state, moveChoice)) { log_log("getGraphsMove: Converting taken corner edge %d to %d.\n", moveChoice, getCorrespondingCornerEdge(moveChoice)); moveChoice = getCorrespondingCornerEdge(moveChoice); } return moveChoice; }
void coe_logMatrix( log_logLevel_t logLevel , const coe_coefMatrix_t A , unsigned int m , unsigned int n , const tbv_tableOfVariables_t * const pTableOfVars ) { /* All logging is done at given level; we can take a shortcut if this verbosity is not desired. */ if(!log_checkLogLevel(_log, logLevel)) return; log_logLine(_log, logLevel, "The linear equation system (%u, %u):", m, n); unsigned int row; for(row=0; row<m; ++row) { LOG_DEBUG(_log, " Row %u:", row); unsigned int col; for(col=0; col<n; ++col) { log_log(_log, logLevel, " (%2d,%2d): ", row, col); coe_logCoefficient( A[row][col] , pTableOfVars , /* tabPos */ 13 + log_getLengthOfLineHeader(_log) ); log_log(_log, log_continueLine, "\n"); } } log_flush(_log); } /* End of coe_logMatrix */
/** * Indicates whether or not the anti-denial-of-service attack feature is * enabled. * * @retval 0 The feature is disabled. * @retval 1 The feature is enabled. */ int isAntiDosEnabled(void) { static int isEnabled; static int isSet = 0; if (!isSet) { int status = reg_getBool(REG_ANTI_DOS, &isEnabled); if (status) { isEnabled = 1; LOG_ADD1("Using default value: %s", isEnabled ? "TRUE" : "FALSE"); if (status == ENOENT) { log_log(LOG_INFO); isSet = 1; } else { log_log(LOG_ERR); } } else { isSet = 1; } } return isEnabled; }
/** * Runs the test cases for the logging system. * @return */ int logging_system_tests() { puts("**********************************************************"); puts("**** Running logging system tests ****"); puts("**********************************************************"); puts(""); puts("TEST CASE 1: "); int level = log_log(LOG_DEBUG, "\tdebug"); if (level == 0) printf("OK\n"); else { printf("FAILED! Expected no output with logging system uninitialized but log_write_log returned %d\n", level); return EXIT_FAILURE; } log_set_level(LOG_DEBUG); puts("TEST CASE 2: "); level = log_log(LOG_DEBUG, "test message debug"); if (level == LOG_DEBUG) printf("OK\n"); else { printf("FAILED! Expected DEBUG but log_write_log returned %d\n", level); return EXIT_FAILURE; } log_set_level(LOG_INFO); level = log_log(LOG_INFO, "test message info"); puts("TEST CASE 3: "); if (level == LOG_INFO) printf("OK\n"); else { printf("FAILED! Expected INFO but log_write_log returned %d\n", level); return EXIT_FAILURE; } puts("TEST CASE 4: "); level = log_log(LOG_DEBUG, "test message debug"); if (level == 0) printf("OK\n"); else { printf("FAILED! Expected no output but log_write_log returned %d\n", level); return EXIT_FAILURE; } level = log_log(LOG_ERROR, "test message error"); puts("TEST CASE 5: "); if (level == LOG_ERROR) printf("OK\n"); else { printf("FAILED! Expected ERROR but log_write_log returned %d\n", level); return EXIT_FAILURE; } return EXIT_SUCCESS; }
/* function to disable lookups through the nss_ldap module to avoid lookup loops */ static void disable_nss_ldap(void) { void *handle; char *error; char **version_info; int *enable_flag; /* try to load the NSS module */ #ifdef RTLD_NODELETE handle = dlopen(NSS_LDAP_SONAME, RTLD_LAZY | RTLD_NODELETE); #else /* not RTLD_NODELETE */ handle = dlopen(NSS_LDAP_SONAME, RTLD_LAZY); #endif /* RTLD_NODELETE */ if (handle == NULL) { log_log(LOG_WARNING, "Warning: NSS_LDAP module not loaded: %s", dlerror()); return; } /* clear any existing errors */ dlerror(); /* lookup the NSS version if possible */ version_info = (char **)dlsym(handle, "_nss_ldap_version"); error = dlerror(); if ((version_info != NULL) && (error == NULL)) log_log(LOG_DEBUG, "NSS_LDAP %s %s", version_info[0], version_info[1]); else log_log(LOG_WARNING, "Warning: NSS_LDAP version missing: %s", error); /* clear any existing errors */ dlerror(); /* try to look up the flag */ enable_flag = (int *)dlsym(handle, "_nss_ldap_enablelookups"); error = dlerror(); if ((enable_flag == NULL) || (error != NULL)) { log_log(LOG_WARNING, "Warning: %s (probably older NSS module loaded)", error); /* fall back to changing the way host lookup is done */ #ifdef HAVE___NSS_CONFIGURE_LOOKUP if (__nss_configure_lookup("hosts", "files dns")) log_log(LOG_ERR, "unable to override hosts lookup method: %s", strerror(errno)); #endif /* HAVE___NSS_CONFIGURE_LOOKUP */ dlclose(handle); return; } /* disable nss_ldap */ *enable_flag = 0; #ifdef RTLD_NODELETE /* only close the handle if RTLD_NODELETE was used */ dlclose(handle); #endif /* RTLD_NODELETE */ }
static long to_date(const char *dn, const char *date, const char *attr) { char buffer[32]; long value; char *tmp; size_t l; /* do some special handling for date values on AD */ if (strcasecmp(attr, "pwdLastSet") == 0) { /* we expect an AD 64-bit datetime value; we should do date=date/864000000000-134774 but that causes problems on 32-bit platforms, first we devide by 1000000000 by stripping the last 9 digits from the string and going from there */ l = strlen(date) - 9; if (l > (sizeof(buffer) - 1)) return -1; /* error */ strncpy(buffer, date, l); buffer[l] = '\0'; errno = 0; value = strtol(buffer, &tmp, 10); if ((*date == '\0') || (*tmp != '\0')) { log_log(LOG_WARNING, "%s: %s: non-numeric", dn, attr); return -1; } else if (errno != 0) { log_log(LOG_WARNING, "%s: %s: out of range", dn, attr); return -1; } return value / 864 - 134774; /* note that AD does not have expiry dates but a lastchangeddate and some value that needs to be added */ } errno = 0; value = strtol(date, &tmp, 10); if ((*date == '\0') || (*tmp != '\0')) { log_log(LOG_WARNING, "%s: %s: non-numeric", dn, attr); return -1; } else if (errno != 0) { log_log(LOG_WARNING, "%s: %s: out of range", dn, attr); return -1; } return value; }
const char *attmap_get_value(MYLDAP_ENTRY *entry, const char *attr, char *buffer, size_t buflen) { const char **values; /* check and clear buffer */ if ((buffer == NULL) || (buflen <= 0)) return NULL; buffer[0] = '\0'; /* for simple values just return the attribute */ if (attr[0] != '"') { values = myldap_get_values(entry, attr); if ((values == NULL) || (values[0] == NULL)) return NULL; strncpy(buffer, values[0], buflen); buffer[buflen - 1] = '\0'; return buffer; /* TODO: maybe warn when multiple values are found */ } /* we have an expression, try to parse */ if ((attr[strlen(attr) - 1] != '"') || (expr_parse(attr + 1, buffer, buflen, entry_expand, (void *)entry) == NULL)) { log_log(LOG_ERR, "attribute mapping %s is invalid", attr); buffer[0] = '\0'; return NULL; } /* strip trailing " */ if (buffer[strlen(buffer) - 1] == '"') buffer[strlen(buffer) - 1] = '\0'; return buffer; }
/* poke the OOM killer so nslcd will never get killed */ static void adjust_oom_score(void) { int oom_adj_fd; if ((oom_adj_fd = open(OOM_SCORE_ADJ_FILE, O_WRONLY)) >= 0) { if (write(oom_adj_fd, OOM_SCORE_ADJ, strlen(OOM_SCORE_ADJ)) < 0) log_log(LOG_WARNING, "writing oom score adjustment of %s failed: %s", OOM_SCORE_ADJ, strerror(errno)); close(oom_adj_fd); } else { log_log(LOG_DEBUG, "could not open %s to adjust the OOM score: %s", OOM_SCORE_ADJ_FILE, strerror(errno)); } }
void ns_sdrop(IRC_User *s, IRC_User *u) { u_int32_t source_snid; u_int32_t snid; char *nick; nick = strtok(NULL, " "); CHECK_IF_IDENTIFIED_NICK if(!is_sadmin(source_snid)) send_lang(u, s, ONLY_FOR_SADMINS); else if(IsNull(nick)) send_lang(u, s, NICK_SDROP_SYNTAX); else if((snid = nick2snid(nick)) == 0) send_lang(u, s, NICK_X_NOT_REGISTERED, nick); else { IRC_User *target = irc_FindUser(nick); drop_nick(snid, nick); if(target && target->snid) { target->snid = 0; target->status = 0; target->flags = 0; irc_SvsMode(target, s, "-r"); } log_log(ns_log, mod_info.name, "%s SDROPPED nick: %s", u->nick, nick); send_lang(u, s, NICK_SDROPPED, nick); } }
void shadow_init(void) { int i; SET *set; /* set up search bases */ if (shadow_bases[0] == NULL) for (i = 0; i < NSS_LDAP_CONFIG_MAX_BASES; i++) shadow_bases[i] = nslcd_cfg->bases[i]; /* set up scope */ if (shadow_scope == LDAP_SCOPE_DEFAULT) shadow_scope = nslcd_cfg->scope; /* set up attribute list */ set = set_new(); attmap_add_attributes(set, attmap_shadow_uid); attmap_add_attributes(set, attmap_shadow_userPassword); attmap_add_attributes(set, attmap_shadow_shadowLastChange); attmap_add_attributes(set, attmap_shadow_shadowMax); attmap_add_attributes(set, attmap_shadow_shadowMin); attmap_add_attributes(set, attmap_shadow_shadowWarning); attmap_add_attributes(set, attmap_shadow_shadowInactive); attmap_add_attributes(set, attmap_shadow_shadowExpire); attmap_add_attributes(set, attmap_shadow_shadowFlag); shadow_attrs = set_tolist(set); if (shadow_attrs == NULL) { log_log(LOG_CRIT, "malloc() failed to allocate memory"); exit(EXIT_FAILURE); } set_free(set); }
static void test_msm_destroy(void) { int status = msm_destroy(); log_log(LOG_ERR); CU_ASSERT_EQUAL(status, 0); }
/* * Resets the backend database. This function shall be called only when * nothing holds the database open. * * ARGUMENTS: * path Pathname of the database directory. Shall not be NULL. * The client can free it upon return. * RETURNS: * 0 Success. * EIO Backend database error. "log_start()" called. */ RegStatus beReset( const char* const path) { RegStatus status; assert(NULL != path); if (0 == (status = verifyBackend(path))) { /* * The database is OK. Make a backup copy. */ status = copyDatabase(path, "", ".bck"); } else if (ECANCELED == status) { /* * The backend database needs to be restored. */ log_add("Restoring from backup"); log_log(LOG_NOTICE); if (0 == (status = removeEnvironment(path))) { status = copyDatabase(path, ".bck", ""); } } return status; }
static int write_alias(TFILE *fp,MYLDAP_ENTRY *entry,const char *reqalias) { int32_t tmpint32,tmp2int32,tmp3int32; const char **names,**members; int i; /* get the name of the alias */ names=myldap_get_values(entry,attmap_alias_cn); if ((names==NULL)||(names[0]==NULL)) { log_log(LOG_WARNING,"alias entry %s does not contain %s value", myldap_get_dn(entry),attmap_alias_cn); return 0; } /* get the members of the alias */ members=myldap_get_values(entry,attmap_alias_rfc822MailMember); /* for each name, write an entry */ for (i=0;names[i]!=NULL;i++) { if ((reqalias==NULL)||(strcasecmp(reqalias,names[i])==0)) { WRITE_INT32(fp,NSLCD_RESULT_BEGIN); WRITE_STRING(fp,names[i]); WRITE_STRINGLIST(fp,members); } } return 0; }
/* provide a wrapper around ldap_init() if the system doesn't have ldap_initialize() */ int ldap_initialize(LDAP **ldp,const char *url) { char host[80]; /* check schema part */ if (strncasecmp(url,"ldap://",7)==0) { strncpy(host,url+7,sizeof(host)); host[sizeof(host)-1]='\0'; } else if (strncasecmp(url,"ldaps://",8)==0) { strncpy(host,url+8,sizeof(host)); host[sizeof(host)-1]='\0'; } else { log_log(LOG_ERR,"ldap_initialize(): schema not supported: %s",url); exit(EXIT_FAILURE); } /* strip trailing slash */ if ((strlen(host)>0)&&(host[strlen(host)-1]=='/')) host[strlen(host)-1]='\0'; /* call ldap_init() */ *ldp=ldap_init(host,LDAP_PORT); return (*ldp==NULL)?LDAP_OPERATIONS_ERROR:LDAP_SUCCESS; }
static void test_msm_init(void) { int status = msm_init(); log_log(LOG_ERR); CU_ASSERT_EQUAL_FATAL(status, 0); }
static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { DIR *dp; struct dirent *de; char *data = malloc(strlen(path)+100); sprintf(data, "readdir:%s:%d:\n", path, (int) offset); log_log(data, fuse_get_context()->pid); free(data); //log_log("readdir\n"); (void) offset; (void) fi; dp = opendir(path); if (dp == NULL) return -errno; while ((de = readdir(dp)) != NULL) { struct stat st; memset(&st, 0, sizeof(st)); st.st_ino = de->d_ino; st.st_mode = de->d_type << 12; if (filler(buf, de->d_name, &st, 0)) break; } closedir(dp); return 0; }
static pid_t run_child(int argc, char *argv[]) { pid_t pid; if(ulogIsDebug()) { char command[1024]; size_t left = sizeof(command) - 1; int ii; command[0] = 0; for (ii = 0; ii < argc; ++ii) { size_t nbytes; if (ii > 0) { (void)strncat(command, " ", left); left -= (1 <= left) ? 1 : left; } (void)strncat(command, argv[ii], left); nbytes = strlen(argv[ii]); left -= (nbytes <= left) ? nbytes : left; } udebug("exec'ing: \"%s\"", command); } pid = ldmfork(); if(pid == -1) { log_log(LOG_ERR); return pid; } if(pid == 0) { /* child */ const unsigned ulogOptions = ulog_get_options(); const char* ulogIdent = getulogident(); const unsigned ulogFacility = getulogfacility(); const char* ulogPath = getulogpath(); (void)signal(SIGCHLD, SIG_DFL); (void)signal(SIGTERM, SIG_DFL); /* keep same descriptors as parent */ /* don't let child get real privilege */ endpriv(); (void) execvp(argv[0], &argv[0]); openulog(ulogIdent, ulogOptions, ulogFacility, ulogPath); serror("run_child: execvp: %s", argv[0]); _exit(127); } /* else, parent */ return pid; }
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) { int res; char *data = malloc(strlen(path)+100); sprintf(data, "mknod:%s:%d:\n", path, mode); log_log(data, fuse_get_context()->pid); free(data); //log_log("mknod\n"); /* On Linux this could just be 'mknod(path, mode, rdev)' but this is more portable */ if (S_ISREG(mode)) { res = open(path, O_CREAT | O_EXCL | O_WRONLY, mode); if (res >= 0) res = close(res); } else if (S_ISFIFO(mode)) res = mkfifo(path, mode); else res = mknod(path, mode, rdev); if (res == -1) return -errno; return 0; }
/* s = service the command was sent to u = user the command was sent from */ void cs_register(IRC_User *s, IRC_User *u) { u_int32_t source_snid; ChanRecord* cr = NULL; IRC_Chan *chan; char *cname; cname = strtok(NULL, " "); CHECK_IF_IDENTIFIED_NICK if(NickSecurityCode && !IsAuthenticated(u)) send_lang(u, s, NEEDS_AUTH_NICK); else if(IsNull(cname)) send_lang(u, s, CHAN_REGISTER_SYNTAX); else if((chan = irc_FindChan(cname)) == NULL) send_lang(u, s, CHAN_X_IS_EMPTY, cname); else if((cr = OpenCR(cname))) send_lang(u, s, CHAN_X_ALREADY_REGISTERED, cname); else if(!irc_IsChanOp(u, chan)) send_lang(u, s, CHAN_NOT_OP); else if(chans_count(source_snid) >= MaxChansPerUser && !(is_sadmin(source_snid))) send_lang(u, s, REACHED_MAX_CHANS_X, MaxChansPerUser); else /* everything is valid lets do the registraion */ { log_log(cs_log, mod_info.name, "Channel %s registered by %s", cname, u->nick); cr = CreateCR(cname); if(IsNull(cr)) { send_lang(u, s, UPDATE_FAIL); return; } cr->flags = 0; cr->t_reg = irc_CurrentTime; cr->t_last_use = irc_CurrentTime; cr->t_ltopic = irc_CurrentTime; cr->t_maxusers = irc_CurrentTime; cr->maxusers = chan->users_count; if(DefaultMlock) cr->mlock = strdup(DefaultMlock); cr->founder = u->snid; if(UpdateCR(cr) == 0) send_lang(u, s, UPDATE_FAIL); else { irc_ChanMode(csu->u, chan, "+r"); irc_ChanUMode(csu->u, chan, "+a" , u); send_lang(u, s, CHAN_X_REGISTER_SUCCESS, cname); mod_do_event(e_chan_register, u, cr); } chan->sdata = cr; if(cr->mlock) { irc_ChanMLockSet(s, chan, cr->mlock); irc_ChanMLockApply(s, chan); } } }
/* * Called by libmonit on Exception. Log * error and abort the application */ void vLogAbortHandler(const char *s, va_list ap) { va_list ap_copy; ASSERT(s); va_copy(ap_copy, ap); log_log(LOG_CRIT, s, ap); va_end(ap_copy); abort(); }
/* Internal Functions */ void drop_nick(u_int32_t snid, char* nick) { log_log(ns_log, mod_info.name, "Dropping snid %d, nick %s", snid, nick); /* call related actions */ mod_do_event(e_nick_delete, &snid, NULL); /* and delete it */ sql_execute("DELETE FROM nickserv WHERE snid=%d", snid); }
// ----------------------------------------------------------------------- static void log_log_timestamp(unsigned component, unsigned level, char *msg) { struct timeval ct; char date[32]; gettimeofday(&ct, NULL); strftime(date, 31, "%Y-%m-%d %H:%M:%S", localtime(&ct.tv_sec)); log_log(component, level, "%s: %s", msg, date); }
/** * Logging interface with priority support * @param s A formated (printf-style) string to log */ void vLogError(const char *s, va_list ap) { va_list ap_copy; ASSERT(s); va_copy(ap_copy, ap); log_log(LOG_ERR, s, ap); va_end(ap_copy); log_backtrace(); }
static void openMsm( McastSessionMemory** msm) { getLdmLogDir_ExpectAndReturn(CWD); *msm = msm_open(SERVICE_ADDR , MCAST_GROUP_ID); log_log(LOG_ERR); OP_ASSERT_TRUE(*msm != NULL); }
void runPlayerStrategyTests() { log_log("RUNNING PLAYER_STRATEGY TESTS\n"); log_log("Testing getRandomMove...\n"); UnscoredState state; stringToUnscoredState(&state, "111101111111111111111111111111111111111111111111111111111111111111111111"); Edge edge = getRandomMove(&state); log_log("getRandomMove returned %d\n", edge); assert(edge == 4); stringToUnscoredState(&state, "100111111111111111111111111111111111111111111111111111111111111111111111"); edge = getRandomMove(&state); assert(edge == 1 || edge == 2); log_log("Testing getFirstBoxCompletingMove...\n"); stringToUnscoredState(&state, "010100000101000000101000000000000000000000000000000000000000000000000000"); edge = getFirstBoxCompletingMove(&state); log_log("getFirstBoxCompletingMove returned %d\n", edge); assert(edge == 10); stringToUnscoredState(&state, "000000000000000000000000000000000000000000000000000000000000000000000000"); edge = getFirstBoxCompletingMove(&state); log_log("getFirstBoxCompletingMove returned %d\n", edge); assert(edge == NO_EDGE); log_log("PLAYER_STRATEGY TESTS COMPLETED\n\n"); }
/** * Logging interface with priority support * @param s A formated (printf-style) string to log */ void LogDebug(const char *s, ...) { ASSERT(s); if (Run.debug) { va_list ap; va_start(ap, s); log_log(LOG_DEBUG, s, ap); va_end(ap); } }
/** * Logging interface with priority support * @param s A formated (printf-style) string to log */ void LogInfo(const char *s, ...) { va_list ap; ASSERT(s); va_start(ap, s); log_log(LOG_INFO, s, ap); va_end(ap); }
static void test_add_get(void) { McastFileId fileA = 1; McastFileId fileB; int status; status = fiq_add(rq, fileA); log_log(LOG_ERR); CU_ASSERT_EQUAL_FATAL(status, 0); CU_ASSERT_EQUAL(fiq_count(rq), 1); status = fiq_removeNoWait(rq, &fileB); log_log(LOG_ERR); CU_ASSERT_EQUAL_FATAL(status, 0); CU_ASSERT_EQUAL_FATAL(fileB, fileA); CU_ASSERT_EQUAL(fiq_count(rq), 0); }