Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #29 from hallyn/2016-02-29/ubuntu
Browse files Browse the repository at this point in the history
2016 02 29/ubuntu
  • Loading branch information
hallyn committed Mar 1, 2016
2 parents 37b74b8 + 832f678 commit e136446
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions pam/pam_cgm.c
Expand Up @@ -4,9 +4,8 @@
* Author: Serge Hallyn <serge.hallyn@ubuntu.com>
*
* When a user logs in, this pam module will create cgroups which
* the user may administer, for all controllers except name=systemd,
* or for any controllers listed on the command line (if any are
* listed).
* the user may administer, for any controllers listed on the command
* line or, if none are listed, then all available controllers.
*
* The cgroup created will be "user/$user/0" for the first session,
* "user/$user/1" for the second, etc.
Expand Down Expand Up @@ -62,19 +61,25 @@ static void get_active_controllers(void)
return;
}
for (i = 0; list[i]; i++) {
if (strcmp(list[i], "name=systemd") == 0)
continue;
NIH_MUST( nih_strcat_sprintf(&ctrl_list, NULL, "%s%s",
ctrl_list ? "," : "", list[i]) );
}
}

static bool is_in_list(char *which, char **list) {
int i;
size_t wlen = strlen(which);

for (i = 0; list[i]; i++) {
if (strcmp(which, list[i]) == 0)
return true;
char *o = list[i];
while (o) {
char *p = index(o, ',');
size_t len = p ? p - o : strlen(o);

if (len == wlen && strncmp(o, which, wlen) == 0)
return true;
o = p ? p + 1 : NULL;
}
}
return false;
}
Expand Down Expand Up @@ -191,8 +196,14 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
mysyslog(LOG_ERR, "Failed to connect to cgmanager\n");
return PAM_SESSION_ERR;
}
if (argc > 1 && strcmp(argv[0], "-c") == 0)
if (argc > 1 && strcmp(argv[0], "-c") == 0) {
ctrl_list = validate_and_dup(argv[1]);
if (!ctrl_list) {
cgm_dbus_disconnect();
mysyslog(LOG_ERR, "PAM-CGM: bad controller arguments\n");
return PAM_SESSION_ERR;
}
}
if (!ctrl_list)
get_active_controllers();
cgm_escape();
Expand Down

0 comments on commit e136446

Please sign in to comment.