int log_opensyslog(const char *fn) { int res = 0; if (set_facility != -1) facility = set_facility; if (fn) { memset(systemlog_fn, '\0', sizeof(systemlog_fn)); sstrncpy(systemlog_fn, fn, sizeof(systemlog_fn)); } if (!*systemlog_fn) { /* The child may have inherited a valid socket from the parent. */ pr_closelog(syslog_sockfd); if ((syslog_sockfd = pr_openlog("proftpd", LOG_NDELAY|LOG_PID, facility)) < 0) return -1; systemlog_fd = -1; } else if ((res = pr_log_openfile(systemlog_fn, &systemlog_fd, PR_LOG_SYSTEM_MODE)) < 0) { memset(systemlog_fn, '\0', sizeof(systemlog_fn)); return res; } syslog_open = TRUE; return 0; }
int xferlog_open(const char *path) { if (path == NULL) { if (xferlogfd != -1) { xferlog_close(); } return 0; } if (xferlogfd == -1) { pr_log_debug(DEBUG6, "opening TransferLog '%s'", path); pr_log_openfile(path, &xferlogfd, PR_TUNABLE_XFER_LOG_MODE); if (xferlogfd < 0) { int xerrno = errno; pr_log_pri(PR_LOG_NOTICE, "unable to open TransferLog '%s': %s", path, strerror(xerrno)); errno = xerrno; } } return xferlogfd; }
int log_opensyslog(const char *fn) { int res = 0; if (set_facility != -1) facility = set_facility; if (fn) { memset(systemlog_fn, '\0', sizeof(systemlog_fn)); sstrncpy(systemlog_fn, fn, sizeof(systemlog_fn)); } if (!*systemlog_fn) { /* The child may have inherited a valid socket from the parent. */ pr_closelog(syslog_sockfd); syslog_sockfd = pr_openlog("proftpd", LOG_NDELAY|LOG_PID, facility); if (syslog_sockfd < 0) { int xerrno = errno; (void) pr_trace_msg(trace_channel, 1, "error opening syslog fd: %s", strerror(xerrno)); errno = xerrno; return -1; } /* Find a usable fd for the just-opened socket fd. */ if (syslog_sockfd <= STDERR_FILENO) { res = pr_fs_get_usable_fd(syslog_sockfd); if (res > 0) { (void) close(syslog_sockfd); syslog_sockfd = res; } } (void) fcntl(syslog_sockfd, F_SETFD, FD_CLOEXEC); systemlog_fd = -1; } else if ((res = pr_log_openfile(systemlog_fn, &systemlog_fd, PR_LOG_SYSTEM_MODE)) < 0) { memset(systemlog_fn, '\0', sizeof(systemlog_fn)); return res; } syslog_open = TRUE; return 0; }
int pr_trace_set_file(const char *path) { int res; if (!path) { if (trace_logfd < 0) { errno = EINVAL; return -1; } (void) close(trace_logfd); trace_logfd = -1; return 0; } pr_signals_block(); PRIVS_ROOT res = pr_log_openfile(path, &trace_logfd, 0660); PRIVS_RELINQUISH pr_signals_unblock(); if (res < 0) { if (res == -1) { pr_log_debug(DEBUG1, "unable to open TraceLog '%s': %s", path, strerror(errno)); } else if (res == PR_LOG_WRITABLE_DIR) { pr_log_debug(DEBUG1, "unable to open TraceLog '%s': parent directory is world-writable", path); } else if (res == PR_LOG_SYMLINK) { pr_log_debug(DEBUG1, "unable to open TraceLog '%s': cannot log to a symbolic link", path); } return res; } return 0; }
static int counter_sess_init(void) { config_rec *c; c = find_config(main_server->conf, CONF_PARAM, "CounterEngine", FALSE); if (c != NULL) { counter_engine = *((int *) c->argv[0]); } if (counter_engine == FALSE) { return 0; } c = find_config(main_server->conf, CONF_PARAM, "CounterLog", FALSE); if (c != NULL) { const char *path = c->argv[0]; if (strcasecmp(path, "none") != 0) { int res, xerrno; PRIVS_ROOT res = pr_log_openfile(path, &counter_logfd, 0660); xerrno = errno; PRIVS_RELINQUISH; if (res < 0) { pr_log_debug(DEBUG2, MOD_COUNTER_VERSION ": error opening CounterLog '%s': %s", path, strerror(xerrno)); counter_logfd = -1; } } } /* Find all CounterFile directives for this vhost, and make sure they * have open handles. We need to do this here, and not in a POST_CMD * PASS handler because of the need to open handles that may be outside * of a chroot. */ c = find_config(main_server->conf, CONF_PARAM, "CounterFile", TRUE); while (c != NULL) { int xerrno = 0; const char *area = NULL, *path; pr_fh_t *fh; struct counter_fh *cfh; pr_signals_handle(); path = c->argv[0]; if (c->parent != NULL) { if (c->parent->config_type == CONF_ANON || c->parent->config_type == CONF_DIR) { area = c->parent->name; } else { (void) pr_log_writefile(counter_logfd, MOD_COUNTER_VERSION, "unhandled configuration parent type (%d) for CounterFile, skipping", c->parent->config_type); c = find_config_next(c, c->next, CONF_PARAM, "CounterFile", TRUE); continue; } } else { /* Toplevel CounterFile directive, in "server config" or <VirtualHost> * sections. */ area = "/"; } PRIVS_ROOT fh = pr_fsio_open(path, O_RDWR|O_CREAT); xerrno = errno; PRIVS_RELINQUISH if (fh == NULL) { pr_log_debug(DEBUG1, MOD_COUNTER_VERSION ": error opening CounterFile '%s': %s", path, strerror(xerrno)); counter_engine = FALSE; if (counter_fhs != NULL) { for (cfh = (struct counter_fh *) counter_fhs->xas_list; cfh; cfh = cfh->next) { (void) pr_fsio_close(cfh->fh); } } return 0; } (void) pr_log_writefile(counter_logfd, MOD_COUNTER_VERSION, "opened CounterFile '%s'", path); if (counter_fhs == NULL) { counter_fhs = xaset_create(counter_pool, NULL); } cfh = pcalloc(counter_pool, sizeof(struct counter_fh)); /* Ignore any trailing slash. */ cfh->arealen = strlen(area); if (cfh->arealen > 1 && area[cfh->arealen-1] == '/') { cfh->arealen--; } cfh->area = pstrndup(counter_pool, area, cfh->arealen); /* Mark any areas that use glob(3) characters. */ if (strpbrk(cfh->area, "[*?") != NULL) { cfh->isglob = TRUE; } cfh->fh = fh; xaset_insert(counter_fhs, (xasetmember_t *) cfh); c = find_config_next(c, c->next, CONF_PARAM, "CounterFile", TRUE); } if (counter_fhs == NULL) { (void) pr_log_writefile(counter_logfd, MOD_COUNTER_VERSION, "no CounterFiles configured, disabling module"); counter_engine = FALSE; return 0; } pr_event_register(&counter_module, "core.exit", counter_exit_ev, NULL); /* If mod_vroot is present, we need to do a little more magic to counter * the mod_vroot magic. */ if (pr_module_exists("mod_vroot.c") == TRUE) { pr_event_register(&counter_module, "core.chroot", counter_chroot_ev, NULL); } return 0; }
static int mcache_sess_init(void) { config_rec *c; pr_event_register(&memcache_module, "core.session-reinit", mcache_sess_reinit_ev, NULL); c = find_config(main_server->conf, CONF_PARAM, "MemcacheEngine", FALSE); if (c) { int engine; engine = *((int *) c->argv[0]); if (engine == FALSE) { /* Explicitly disable memcache support for this session */ memcache_set_servers(NULL); return 0; } } pr_event_register(&memcache_module, "core.exit", mcache_exit_ev, NULL); c = find_config(main_server->conf, CONF_PARAM, "MemcacheLog", FALSE); if (c) { const char *path; path = c->argv[0]; if (strcasecmp(path, "none") != 0) { int res, xerrno; pr_signals_block(); PRIVS_ROOT res = pr_log_openfile(path, &memcache_logfd, PR_LOG_SYSTEM_MODE); xerrno = errno; PRIVS_RELINQUISH pr_signals_unblock(); switch (res) { case 0: break; case -1: pr_log_pri(PR_LOG_NOTICE, MOD_MEMCACHE_VERSION ": notice: unable to open MemcacheLog '%s': %s", path, strerror(xerrno)); break; case PR_LOG_WRITABLE_DIR: pr_log_pri(PR_LOG_WARNING, MOD_MEMCACHE_VERSION ": notice: unable to use MemcacheLog '%s': parent directory is " "world-writable", path); break; case PR_LOG_SYMLINK: pr_log_pri(PR_LOG_WARNING, MOD_MEMCACHE_VERSION ": notice: unable to use MemcacheLog '%s': cannot log to a symlink", path); break; } } } c = find_config(main_server->conf, CONF_PARAM, "MemcacheServers", FALSE); if (c) { memcached_server_st *memcache_servers; memcache_servers = c->argv[0]; memcache_set_servers(memcache_servers); } c = find_config(main_server->conf, CONF_PARAM, "MemcacheOptions", FALSE); if (c) { unsigned long flags; flags = *((unsigned long *) c->argv[0]); if (memcache_set_sess_flags(flags) < 0) { (void) pr_log_writefile(memcache_logfd, MOD_MEMCACHE_VERSION, "error setting memcache flags: %s", strerror(errno)); } } c = find_config(main_server->conf, CONF_PARAM, "MemcacheReplicas", FALSE); if (c) { uint64_t count; count = *((uint64_t *) c->argv[0]); if (memcache_set_sess_replicas(count) < 0) { (void) pr_log_writefile(memcache_logfd, MOD_MEMCACHE_VERSION, "error setting memcache replicas: %s", strerror(errno)); } } c = find_config(main_server->conf, CONF_PARAM, "MemcacheTimeouts", FALSE); if (c) { unsigned long conn_millis, read_millis, write_millis, retry_sec; conn_millis = *((unsigned long *) c->argv[0]); read_millis = *((unsigned long *) c->argv[1]); write_millis = *((unsigned long *) c->argv[2]); retry_sec = *((unsigned long *) c->argv[3]); if (memcache_set_timeouts(conn_millis, read_millis, write_millis, retry_sec) < 0) { (void) pr_log_writefile(memcache_logfd, MOD_MEMCACHE_VERSION, "error setting memcache timeouts: %s", strerror(errno)); } } return 0; }