added help message

master
Alessandro Mauri 3 years ago
parent 475aa341c5
commit 37967a87c0
  1. 31
      us.c

31
us.c

@ -87,7 +87,7 @@ struct user_info {
static void *emalloc(size_t); static void *emalloc(size_t);
static char *estrdup(const char *); static char *estrdup(const char *);
void *erealloc(void *, size_t); void *erealloc(void *, size_t);
static void usage(void); static void usage(int);
static void die(const char *, ...); static void die(const char *, ...);
static int perm_set(struct passwd *, struct group *); static int perm_set(struct passwd *, struct group *);
static int authenticate(uid_t, int, int); static int authenticate(uid_t, int, int);
@ -106,7 +106,7 @@ int main(int argc, char *argv[])
struct user_info t_gr_info = {0}, t_pw_info = {0}; struct user_info t_gr_info = {0}, t_pw_info = {0};
int opt, err; int opt, err;
int shellflag = 0, envflag = 0, askpass = 0; int shellflag = 0, envflag = 0, askpass = 0;
while ((opt = getopt(argc, argv, "Au:g:C:se")) != -1) { while ((opt = getopt(argc, argv, "Au:g:C:seh")) != -1) {
switch (opt) { switch (opt) {
case 'A': case 'A':
askpass = 1; askpass = 1;
@ -126,8 +126,12 @@ int main(int argc, char *argv[])
case 'e': case 'e':
envflag = 1; envflag = 1;
break; break;
case 'h':
usage(1);
exit(EXIT_SUCCESS);
break;
case '?': case '?':
usage(); usage(0);
exit(EINVAL); exit(EINVAL);
break; break;
} }
@ -368,17 +372,18 @@ int main(int argc, char *argv[])
return errno; return errno;
} }
static inline void usage(void) static inline void usage(int complete)
{ {
// TODO: planned options printf("usage: us [-hseA] [-u user] [-g group] [-C config] command [args]\n");
// -a [program]: like sudo's askpass if (!complete)
// -u [user]: change the default user from root to user return;
// -g [group]: change the primary group to [gorup] printf("-h print this message\n"
// both -a and -g will accept numbers with #[num] like sudo "-s use the user's shell instead of /bin/sh\n"
// -c [file]: manually select config file "-e keep the user's entire environment\n"
// something about environment "-A use the command in US_ASKPASS as askpass helper\n"
// something about non interactiveness "-u user set new user to 'user' instead of root\n"
printf("usage: us [-seA] [-u user] [-g group] [-C config] command [args]\n"); "-s group set new group to 'group'\n"
"-C config use specifi config file\n");
} }
static int perm_set(struct passwd *pw, struct group *gr) static int perm_set(struct passwd *pw, struct group *gr)

Loading…
Cancel
Save