char *homedir(bool useconf) { static char homedir_buf[DIRMAX] = ""; if (!homedir_buf[0]) { char tmp[DIRMAX] = ""; if (conf.homedir && useconf) simple_snprintf(tmp, sizeof tmp, "%s", conf.homedir); else { #ifdef CYGWIN_HACKS simple_snprintf(tmp, sizeof tmp, "%s", dirname(binname)); #else /* !CYGWIN_HACKS */ struct passwd *pw = NULL; ContextNote(STR("getpwuid()")); pw = getpwuid(myuid); if (pw) simple_snprintf(tmp, sizeof tmp, "%s", pw->pw_dir); ContextNote(STR("getpwuid(): Success")); #endif /* CYGWIN_HACKS */ } ContextNote(STR("realpath()")); if (tmp[0]) realpath(tmp, homedir_buf); /* this will convert lame home dirs of /home/blah->/usr/home/blah */ ContextNote(STR("realpath(): Success")); } return homedir_buf[0] ? homedir_buf : NULL; }
char *move_bin(const char *ipath, const char *file, bool run) { char *path = strdup(ipath); expand_tilde(&path); /* move the binary to the correct place */ static char newbin[DIRMAX] = ""; char real[DIRMAX] = ""; simple_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file); ContextNote(STR("realpath()")); realpath(binname, real); /* get the realpath of binname */ ContextNote(STR("realpath(): Success")); /* running from wrong dir, or wrong bin name.. lets try to fix that :) */ sdprintf(STR("binname: %s"), binname); sdprintf(STR("newbin: %s"), newbin); sdprintf(STR("real: %s"), real); if (strcmp(binname, newbin) && strcmp(newbin, real)) { /* if wrong path and new path != current */ bool ok = 1; sdprintf(STR("wrong dir, is: %s :: %s"), binname, newbin); unlink(newbin); if (copyfile(binname, newbin)) ok = 0; if (ok && !can_stat(newbin)) { unlink(newbin); ok = 0; } if (ok && fixmod(newbin)) { unlink(newbin); ok = 0; } if (ok) { sdprintf(STR("Binary successfully moved to: %s"), newbin); unlink(binname); if (run) { simple_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", shell_escape(file)); system(newbin); sdprintf(STR("exiting to let new binary run...")); exit(0); } } else { if (run) werr(ERR_WRONGBINDIR); sdprintf(STR("Binary move failed to: %s"), newbin); return binname; } } return newbin; }
static bool process_timer(egg_timer_t* timer) { TimerFunc callback = timer->callback; void *client_data = timer->client_data; bool deleted = 0; if (timer->flags & TIMER_REPEAT) { /* Update timer. */ /* This used to be '+= howlong.sec' but, if the time changed say 3 years (happened), this function * would end up executing all timers for 3 years until it is caught up. */ timer->trigger_time.sec = now.sec + timer->howlong.sec; timer->trigger_time.usec = now.usec + timer->howlong.usec; if (timer->trigger_time.usec >= 1000000) { timer->trigger_time.usec -= 1000000; ++(timer->trigger_time.sec); } ++(timer->called); } else { deleted = 1; } if (timer->name) ContextNote("Timer", timer->name); callback(client_data); return deleted; }
char *my_username() { static char username[DIRMAX] = ""; if (!username[0]) { #ifdef CYGWIN_HACKS simple_snprintf(username, sizeof username, "cygwin"); #else /* !CYGWIN_HACKS */ struct passwd *pw = NULL; ContextNote(STR("getpwuid()")); pw = getpwuid(myuid); ContextNote(STR("getpwuid(): Success")); if (pw) strlcpy(username, pw->pw_name, sizeof(username)); #endif /* CYGWIN_HACKS */ } return username[0] ? username : NULL; }
static bool botaddr_set(struct userrec *u, struct user_entry *e, void *buf) { register struct bot_addr *bi = (struct bot_addr *) e->u.extra; if (!bi && !buf) return 1; if (bi != buf) { if (bi) { free(bi->address); free(bi->uplink); free(bi); } ContextNote("botaddr_set", "(sharebug) occurred in botaddr_set"); bi = (struct bot_addr *) buf; e->u.extra = (struct bot_addr *) buf; } if (bi && !noshare) { shareout("c BOTADDR %s %s %d %d %d %s\n",u->handle, (bi->address && bi->address[0]) ? bi->address : "127.0.0.1", bi->telnet_port, bi->relay_port, bi->hublevel, bi->uplink); } return 1; }
void sdprintf (const char *format, ...) { char s[2001] = ""; va_list va; va_start(va, format); egg_vsnprintf(s, sizeof(s), format, va); va_end(va); remove_crlf(s); ContextNote("dbg", s); if (sdebug) { if (!backgrd) dprintf(DP_STDOUT, "[D:%lu] %s%s%s\n", (unsigned long) mypid, BOLD(-1), s, BOLD_END(-1)); else printf("[D:%lu] %s%s%s\n", (unsigned long) mypid, BOLD(-1), s, BOLD_END(-1)); } #ifdef DEBUG logfile(LOG_DEBUG, s); #endif }