From 9f77a439ee79c2302eca6faee2b56583f213c956 Mon Sep 17 00:00:00 2001 From: Mark Grondona <mgrondona@llnl.gov> Date: Mon, 3 Feb 2003 21:39:52 +0000 Subject: [PATCH] o mgr.c: only execute drop_privileges, reclaim_privileges, become_user if running slurmd as root. o shm.c : removed one error message --- src/slurmd/mgr.c | 12 ++++++++++++ src/slurmd/shm.c | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/slurmd/mgr.c b/src/slurmd/mgr.c index 55f56f4d7b9..b0130261714 100644 --- a/src/slurmd/mgr.c +++ b/src/slurmd/mgr.c @@ -495,6 +495,12 @@ _wait_for_all_tasks(slurmd_job_t *job) static int _drop_privileges(struct passwd *pwd) { + /* + * No need to drop privileges if we're not running as root + */ + if (getuid() != (uid_t) 0) + return SLURM_SUCCESS; + if (setegid(pwd->pw_gid) < 0) { error("setegid: %m"); return -1; @@ -515,6 +521,12 @@ _drop_privileges(struct passwd *pwd) static int _reclaim_privileges(struct passwd *pwd) { + /* + * No need to reclaim privileges if our uid == pwd->pw_uid + */ + if (getuid() == pwd->pw_uid) + return SLURM_SUCCESS; + if (seteuid(pwd->pw_uid) < 0) { error("seteuid: %m"); return -1; diff --git a/src/slurmd/shm.c b/src/slurmd/shm.c index fa87dee023b..59de2db64d1 100644 --- a/src/slurmd/shm.c +++ b/src/slurmd/shm.c @@ -190,6 +190,7 @@ shm_cleanup(void) { char *s; key_t key; + int id = -1; if ((s = _create_ipc_name(SHM_LOCKNAME))) { key = ftok(s, 1); @@ -202,11 +203,9 @@ shm_cleanup(void) /* This seems to be the only way to get a shared memory ID given * a key, if you don't already know the size of the region. */ - if ((shmid = shmget(key, 1, 0)) < 0) { - error ("Unable to get shmid: %m"); - } + id = shmget(key, 1, 0); - if ((shmid > 0) && (shmctl(shmid, IPC_RMID, NULL) < 0)) { + if ((id > 0) && (shmctl(shmid, IPC_RMID, NULL) < 0)) { error ("Unable to destroy existing shm segment"); } } -- GitLab