/* Reset slurmdbd logging based upon configuration parameters */ static void _update_logging(bool startup) { /* Preserve execute line arguments (if any) */ if (debug_level) { slurmdbd_conf->debug_level = MIN( (LOG_LEVEL_INFO + debug_level), (LOG_LEVEL_END - 1)); } log_opts.stderr_level = slurmdbd_conf->debug_level; log_opts.logfile_level = slurmdbd_conf->debug_level; log_opts.syslog_level = slurmdbd_conf->debug_level; if (foreground) { log_opts.syslog_level = LOG_LEVEL_QUIET; } else { log_opts.stderr_level = LOG_LEVEL_QUIET; if (!slurmdbd_conf->log_file && (slurmdbd_conf->syslog_debug == LOG_LEVEL_QUIET)) { /* Insure fatal errors get logged somewhere */ log_opts.syslog_level = LOG_LEVEL_FATAL; } else { log_opts.syslog_level = slurmdbd_conf->syslog_debug; } } log_alter(log_opts, SYSLOG_FACILITY_DAEMON, slurmdbd_conf->log_file); log_set_timefmt(slurmdbd_conf->log_fmt); if (startup && slurmdbd_conf->log_file) { int rc; gid_t slurm_user_gid; slurm_user_gid = gid_from_uid(slurmdbd_conf->slurm_user_id); rc = chown(slurmdbd_conf->log_file, slurmdbd_conf->slurm_user_id, slurm_user_gid); if (rc) { error("chown(%s, %d, %d): %m", slurmdbd_conf->log_file, (int) slurmdbd_conf->slurm_user_id, (int) slurm_user_gid); } } debug("Log file re-opened"); }
static void _become_slurm_user(void) { gid_t slurm_user_gid; /* Determine SlurmUser gid */ slurm_user_gid = gid_from_uid(slurmdbd_conf->slurm_user_id); if (slurm_user_gid == (gid_t) -1) { fatal("Failed to determine gid of SlurmUser(%u)", slurmdbd_conf->slurm_user_id); } /* Initialize supplementary groups ID list for SlurmUser */ if (getuid() == 0) { /* root does not need supplementary groups */ if ((slurmdbd_conf->slurm_user_id == 0) && (setgroups(0, NULL) != 0)) { fatal("Failed to drop supplementary groups, " "setgroups: %m"); } else if ((slurmdbd_conf->slurm_user_id != getuid()) && initgroups(slurmdbd_conf->slurm_user_name, slurm_user_gid)) { fatal("Failed to set supplementary groups, " "initgroups: %m"); } } else { info("Not running as root. Can't drop supplementary groups"); } /* Set GID to GID of SlurmUser */ if ((slurm_user_gid != getegid()) && (setgid(slurm_user_gid))) { fatal("Failed to set GID to %d", slurm_user_gid); } /* Set UID to UID of SlurmUser */ if ((slurmdbd_conf->slurm_user_id != getuid()) && (setuid(slurmdbd_conf->slurm_user_id))) { fatal("Can not set uid to SlurmUser(%u): %m", slurmdbd_conf->slurm_user_id); } }
/* * mcs_p_check_mcs_label() is called to check mcs_label. */ extern int mcs_p_check_mcs_label (uint32_t user_id, char *mcs_label) { int rc = SLURM_ERROR; int i = 0; gid_t gid; gid_t slurm_user_gid; uint32_t tmp_group ; gid_t groups[MAX_GROUPS]; uint32_t group_id; int ngroups = -1; if (mcs_label != NULL) { /* test if real unix group */ if (gid_from_string(mcs_label, &gid ) != 0) return rc; /* test if this group is owned by the user */ slurm_user_gid = gid_from_uid(user_id); group_id = (uint32_t) slurm_user_gid; rc = _get_user_groups(user_id, group_id, groups, MAX_GROUPS, &ngroups); if (rc) /* Failed to get groups */ return rc; rc = SLURM_ERROR; for (i = 0; i < ngroups; i++) { tmp_group = (uint32_t) groups[i]; if (gid == tmp_group) { rc = SLURM_SUCCESS; break; } } } else rc = SLURM_SUCCESS; return rc; }
/* Reset slurmctld logging based upon configuration parameters */ static void _update_logging(bool startup) { /* Preserve execute line arguments (if any) */ if (debug_level) { slurmdbd_conf->debug_level = MIN( (LOG_LEVEL_INFO + debug_level), (LOG_LEVEL_END - 1)); } log_opts.stderr_level = slurmdbd_conf->debug_level; log_opts.logfile_level = slurmdbd_conf->debug_level; log_opts.syslog_level = slurmdbd_conf->debug_level; if (foreground) log_opts.syslog_level = LOG_LEVEL_QUIET; else { log_opts.stderr_level = LOG_LEVEL_QUIET; if (slurmdbd_conf->log_file) log_opts.syslog_level = LOG_LEVEL_QUIET; } log_alter(log_opts, SYSLOG_FACILITY_DAEMON, slurmdbd_conf->log_file); if (startup && slurmdbd_conf->log_file) { int rc; gid_t slurm_user_gid; slurm_user_gid = gid_from_uid(slurmdbd_conf->slurm_user_id); rc = chown(slurmdbd_conf->log_file, slurmdbd_conf->slurm_user_id, slurm_user_gid); if (rc) { error("chown(%s, %d, %d): %m", slurmdbd_conf->log_file, (int) slurmdbd_conf->slurm_user_id, (int) slurm_user_gid); } } }