void pr_session_disconnect(module *m, int reason_code, const char *details) { session.disconnect_reason = reason_code; session.disconnect_module = m; if (details != NULL && session.notes != NULL) { /* Stash any extra details in the session.notes table */ if (pr_table_add_dup(session.notes, "core.disconnect-details", (char *) details, 0) < 0) { int xerrno = errno; if (xerrno != EEXIST) { pr_log_debug(DEBUG5, "error stashing 'core.disconnect-details' in " "session.notes: %s", strerror(xerrno)); } } } pr_session_end(0); }
MODRET add_lmd_allow_user(cmd_rec *cmd) { config_rec *c; int i; pr_table_t *explicit_users; if(cmd->argc < 2) CONF_ERROR(cmd, "missing argument"); CHECK_CONF(cmd, CONF_ROOT|CONF_GLOBAL); /* argv => LMDBAllowedUser nobody nobody1 nobody2 */ c = find_config(main_server->conf, CONF_PARAM, "LMDBAllowedUser", FALSE); if(c && c->argv[0]) { explicit_users = c->argv[0]; } else { c = add_config_param(cmd->argv[0], 0, NULL); c->argv[0] = explicit_users = pr_table_alloc(main_server->pool, 0); } for(i=1; i < cmd->argc; i++) { const char *account = pstrdup(main_server->pool, cmd->argv[i]); if(pr_table_exists(explicit_users, account) > 0) { pr_log_debug(DEBUG2, "%s: %s is already registerd", MODULE_NAME, account); continue; } if(pr_table_add_dup(explicit_users, account, "y", 0) < 0){ pr_log_pri(PR_LOG_ERR, "%s: failed pr_table_add_dup(): %s", MODULE_NAME, strerror(errno)); exit(1); } pr_log_debug(DEBUG2, "%s: add LMDBAllowedUser[%d] %s", MODULE_NAME, i, account); } return PR_HANDLED(cmd); }
int vroot_fsio_chroot(pr_fs_t *fs, const char *path) { char base[PR_TUNABLE_PATH_MAX + 1]; char *chroot_path = "/", *tmp = NULL; config_rec *c; size_t baselen = 0; if (path == NULL || *path == '\0') { errno = EINVAL; return -1; } memset(base, '\0', sizeof(base)); if (path[0] == '/' && path[1] == '\0') { /* chrooting to '/', nothing needs to be done. */ return 0; } c = find_config(main_server->conf, CONF_PARAM, "VRootServerRoot", FALSE); if (c != NULL) { int res; char *server_root, *ptr = NULL; server_root = c->argv[0]; /* If the last character in the configured path is a slash, remove * it temporarily. */ if (server_root[strlen(server_root)-1] == '/') { ptr = &(server_root[strlen(server_root)-1]); *ptr = '\0'; } /* Now, make sure that the given path is below the configured * VRootServerRoot. If so, then we perform a real chroot to the * VRootServerRoot directory, then use vroots from there. */ res = strncmp(path, server_root, strlen(server_root)); if (ptr != NULL) { *ptr = '/'; } if (res == 0) { (void) pr_log_writefile(vroot_logfd, MOD_VROOT_VERSION, "chroot path '%s' within VRootServerRoot '%s', " "chrooting to VRootServerRoot", path, server_root); if (chroot(server_root) < 0) { int xerrno = errno; (void) pr_log_writefile(vroot_logfd, MOD_VROOT_VERSION, "error chrooting to VRootServerRoot '%s': %s", server_root, strerror(xerrno)); errno = xerrno; return -1; } pr_fs_clean_path(path + strlen(server_root), base, sizeof(base)); chroot_path = server_root; } else { (void) pr_log_writefile(vroot_logfd, MOD_VROOT_VERSION, "chroot path '%s' is not within VRootServerRoot '%s', " "not chrooting to VRootServerRoot", path, server_root); pr_fs_clean_path(path, base, sizeof(base)); } } else { pr_fs_clean_path(path, base, sizeof(base)); } tmp = base; /* Advance to the end of the path. */ while (*tmp != '\0') { tmp++; } for (;;) { tmp--; pr_signals_handle(); if (tmp == base || *tmp != '/') { break; } *tmp = '\0'; } baselen = strlen(base); if (baselen >= PR_TUNABLE_PATH_MAX) { errno = ENAMETOOLONG; return -1; } /* Store the base path in the session notes, for use by e.g. other modules. */ if (pr_table_add_dup(session.notes, "mod_vroot.chroot-path", base, 0) < 0) { pr_trace_msg(trace_channel, 3, "error stashing 'mod_vroot.chroot-path' in session.notes: %s", strerror(errno)); } vroot_path_set_base(base, baselen); session.chroot_path = pstrdup(session.pool, chroot_path); return 0; }