diff --git a/us.c b/us.c index 04e1bf9..8b752b6 100644 --- a/us.c +++ b/us.c @@ -158,6 +158,10 @@ int main(int argc, char *argv[]) if (!t_pw) die("user_to_passwd:"); t_gr = group_to_grp(t_grp, &t_gr_info); + gid_t t_groups[GROUPS_MAX]; + int nt_groups = GROUPS_MAX; + if (getgrouplist(t_pw->pw_name, t_pw->pw_gid, t_groups, &nt_groups) == -1) + die("getgrouplist:"); /* Don't have to wait for children */ struct sigaction sa = {0}; @@ -186,6 +190,7 @@ int main(int argc, char *argv[]) struct user_info who_info = {0}, as_info = {0}; int who_usr = conf[i].who[0] == ':' ? 0 : 1; int as_usr = conf[i].as[0] == ':' ? 0 : 1; + if (who_usr) { who_pw = user_to_passwd(conf[i].who, &who_info); if (!who_pw) @@ -193,13 +198,13 @@ int main(int argc, char *argv[]) if (my_pw->pw_uid != who_pw->pw_uid) continue; } else { - who_gr = group_to_grp(conf[i].who, &who_info); + who_gr = group_to_grp(conf[i].who+1, &who_info); if (!who_gr) die("%s not a valid group", conf[i].who); gid_t w_gid = who_gr->gr_gid; int x = 0; for (; x < n_groups && w_gid != my_groups[x]; x++); - if (w_gid != my_groups[x]) + if (x == n_groups) continue; } @@ -209,14 +214,15 @@ int main(int argc, char *argv[]) die("%s not a valid user", conf[i].as); if (t_pw->pw_uid != as_pw->pw_uid) continue; - } else if (t_gr) { - as_gr = group_to_grp(conf[i].as, &as_info); + } else { + as_gr = group_to_grp(conf[i].as+1, &as_info); if (!as_gr) die("%s not a valid group", conf[i].as); - if (t_gr->gr_gid != as_gr->gr_gid) + gid_t a_gid = as_gr->gr_gid; + int x = 0; + for (; x < nt_groups && a_gid != t_groups[x]; x++); + if (x == nt_groups) continue; - } else { - continue; } here = 1; if (conf[i].type == 0) @@ -382,7 +388,7 @@ static inline void usage(int complete) "-e keep the user's entire environment\n" "-A use the command in US_ASKPASS as askpass helper\n" "-u user set new user to 'user' instead of root\n" - "-s group set new group to 'group'\n" + "-g group set new group to 'group'\n" "-C config use specifi config file\n"); } @@ -746,7 +752,7 @@ static int get_config(struct config **conf, int *num) struct config c = {0}; for (s = line;; s = NULL, n++) { int getflags = 0; - if (!(t = strtok_r(s, " ", &sv))) + if (!(t = strtok_r(s, " \t", &sv))) break; if (*t == '#') break;