Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Slurm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tud-zih-energy
Slurm
Commits
2937b833
Commit
2937b833
authored
16 years ago
by
Moe Jette
Browse files
Options
Downloads
Patches
Plain Diff
svn merge -r17175:17177
https://eris.llnl.gov/svn/slurm/branches/slurm-1.3
parent
21c4e603
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/common/uid.c
+18
-0
18 additions, 0 deletions
src/common/uid.c
src/common/uid.h
+6
-0
6 additions, 0 deletions
src/common/uid.h
src/slurmctld/controller.c
+37
-37
37 additions, 37 deletions
src/slurmctld/controller.c
src/slurmd/slurmd/slurmd.c
+13
-0
13 additions, 0 deletions
src/slurmd/slurmd/slurmd.c
with
74 additions
and
37 deletions
src/common/uid.c
+
18
−
0
View file @
2937b833
...
@@ -111,6 +111,24 @@ uid_to_string (uid_t uid)
...
@@ -111,6 +111,24 @@ uid_to_string (uid_t uid)
return
ustring
;
return
ustring
;
}
}
gid_t
gid_from_uid
(
uid_t
uid
)
{
struct
passwd
pwd
,
*
result
;
char
buffer
[
PW_BUF_SIZE
];
gid_t
gid
;
int
rc
;
rc
=
getpwuid_r
(
uid
,
&
pwd
,
buffer
,
PW_BUF_SIZE
,
&
result
);
if
(
result
==
NULL
)
{
gid
=
(
gid_t
)
-
1
;
}
else
{
gid
=
result
->
pw_gid
;
}
return
gid
;
}
gid_t
gid_t
gid_from_string
(
char
*
name
)
gid_from_string
(
char
*
name
)
{
{
...
...
This diff is collapsed.
Click to expand it.
src/common/uid.h
+
6
−
0
View file @
2937b833
...
@@ -60,6 +60,12 @@
...
@@ -60,6 +60,12 @@
*/
*/
uid_t
uid_from_string
(
char
*
name
);
uid_t
uid_from_string
(
char
*
name
);
/*
* Return the primary group id for a given user id, or
* (gid_t) -1 on failure.
*/
gid_t
gid_from_uid
(
uid_t
uid
);
/*
/*
* Same as uid_from_name(), but for group name/id.
* Same as uid_from_name(), but for group name/id.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
src/slurmctld/controller.c
+
37
−
37
View file @
2937b833
...
@@ -194,7 +194,7 @@ inline static void _update_cred_key(void);
...
@@ -194,7 +194,7 @@ inline static void _update_cred_key(void);
inline
static
void
_usage
(
char
*
prog_name
);
inline
static
void
_usage
(
char
*
prog_name
);
static
bool
_wait_for_server_thread
(
void
);
static
bool
_wait_for_server_thread
(
void
);
static
void
*
_assoc_cache_mgr
(
void
*
no_data
);
static
void
*
_assoc_cache_mgr
(
void
*
no_data
);
static
int
_become_slurm_user
(
void
);
static
void
_become_slurm_user
(
void
);
typedef
struct
connection_arg
{
typedef
struct
connection_arg
{
int
newsockfd
;
int
newsockfd
;
...
@@ -231,11 +231,7 @@ int main(int argc, char *argv[])
...
@@ -231,11 +231,7 @@ int main(int argc, char *argv[])
* able to write a core dump.
* able to write a core dump.
*/
*/
_init_pidfile
();
_init_pidfile
();
_become_slurm_user
();
if
(
_become_slurm_user
()
<
0
)
fatal
(
"Unable to assume slurm user (%s:%d) identity"
,
slurmctld_conf
.
slurm_user_name
,
slurmctld_conf
.
slurm_user_id
);
if
(
stat
(
slurmctld_conf
.
mail_prog
,
&
stat_buf
)
!=
0
)
if
(
stat
(
slurmctld_conf
.
mail_prog
,
&
stat_buf
)
!=
0
)
error
(
"Configured MailProg is invalid"
);
error
(
"Configured MailProg is invalid"
);
...
@@ -1751,42 +1747,46 @@ static void *_assoc_cache_mgr(void *no_data)
...
@@ -1751,42 +1747,46 @@ static void *_assoc_cache_mgr(void *no_data)
return
NULL
;
return
NULL
;
}
}
static
int
_become_slurm_user
(
void
)
static
void
_become_slurm_user
(
void
)
{
{
uid_t
uid
;
gid_t
slurm_user_gid
;
gid_t
gid
;
const
char
*
username
;
struct
passwd
*
pwd
;
uid
=
slurmctld_conf
.
slurm_user_id
;
username
=
slurmctld_conf
.
slurm_user_name
;
if
((
pwd
=
getpwuid
(
uid
))
==
NULL
)
return
error
(
"getpwuid(%d): %m"
,
(
int
)
uid
);
gid
=
pwd
->
pw_gid
;
/*
* Warning: we can't call initgroups here becuase we don't
* have proper perms. However, this probably means slurmctld
* was already started as the slurm user, so this is most
* likely safe.
*/
if
(
getuid
()
==
uid
&&
getgid
()
==
gid
)
return
(
0
);
if
(
setgid
(
gid
)
<
0
)
/* Determine SlurmUser gid */
return
error
(
"Failed to set gid to slurm gid (%d): %m"
,
slurm_user_gid
=
gid_from_uid
(
slurmctld_conf
.
slurm_user_id
);
(
int
)
gid
);
if
(
slurm_user_gid
==
(
gid_t
)
-
1
)
{
fatal
(
"Failed to determine gid of SlurmUser(%d)"
,
slurm_user_gid
);
}
if
(
initgroups
(
username
,
gid
)
<
0
)
/* Initialize supplementary groups ID list for SlurmUser */
return
error
(
"initgroups: %m"
);
if
(
getuid
()
==
0
)
{
/* root does not need supplementary groups */
if
((
slurmctld_conf
.
slurm_user_id
==
0
)
&&
(
setgroups
(
0
,
NULL
)
!=
0
))
{
fatal
(
"Failed to drop supplementary groups, "
"setgroups: %m"
);
}
else
if
((
slurmctld_conf
.
slurm_user_id
!=
getuid
())
&&
initgroups
(
slurmctld_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"
);
}
if
(
setuid
(
uid
)
<
0
)
/* Set GID to GID of SlurmUser */
return
error
(
"Failed to setuid to slurm uid (%d): %m"
,
if
((
slurm_user_gid
!=
getegid
())
&&
(
int
)
uid
);
(
setgid
(
slurm_user_gid
)))
{
fatal
(
"Failed to set GID to %d"
,
slurm_user_gid
);
}
return
(
0
);
/* Set UID to UID of SlurmUser */
if
((
slurmctld_conf
.
slurm_user_id
!=
getuid
())
&&
(
setuid
(
slurmctld_conf
.
slurm_user_id
)))
{
fatal
(
"Can not set uid to SlurmUser(%d): %m"
,
slurmctld_conf
.
slurm_user_id
);
}
}
}
This diff is collapsed.
Click to expand it.
src/slurmd/slurmd/slurmd.c
+
13
−
0
View file @
2937b833
...
@@ -44,6 +44,7 @@
...
@@ -44,6 +44,7 @@
#endif
#endif
#include
<fcntl.h>
#include
<fcntl.h>
#include
<grp.h>
#include
<string.h>
#include
<string.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
<pthread.h>
#include
<pthread.h>
...
@@ -164,6 +165,18 @@ main (int argc, char *argv[])
...
@@ -164,6 +165,18 @@ main (int argc, char *argv[])
for
(
i
=
3
;
i
<
256
;
i
++
)
for
(
i
=
3
;
i
<
256
;
i
++
)
(
void
)
close
(
i
);
(
void
)
close
(
i
);
/*
* Drop supplementary groups.
*/
if
(
geteuid
()
==
0
)
{
if
(
setgroups
(
0
,
NULL
)
!=
0
)
{
fatal
(
"Failed to drop supplementary groups, "
"setgroups: %m"
);
}
}
else
{
info
(
"Not running as root. Can't drop supplementary groups"
);
}
/*
/*
* Create and set default values for the slurmd global
* Create and set default values for the slurmd global
* config variable "conf"
* config variable "conf"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment