- typo in help message
- config not ignoring tabs
- groups not using target user group list
master
Alessandro Mauri 3 years ago
parent 37967a87c0
commit 990136a6a7
  1. 24
      us.c

24
us.c

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

Loading…
Cancel
Save