diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-07-28 20:22:51 +0400 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-07-28 20:22:51 +0400 |
commit | 6150df320a8aa825d88d6382c51017f362f2aabe (patch) | |
tree | ac57f92c33e64d0914dd18f40e40b91cd13f4483 /id.c | |
parent | d5704686b14b9cd5ae588148269cad9d7f3f1e63 (diff) |
Some cleanups, based on a patch from Ken Chalmers
-Erik
Diffstat (limited to 'id.c')
-rw-r--r-- | id.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -2,7 +2,6 @@ /* * Mini id implementation for busybox * - * * Copyright (C) 2000 by Randolph Chung <tausq@debian.org> * * This program is free software; you can redistribute it and/or modify @@ -33,7 +32,8 @@ extern int id_main(int argc, char **argv) { int no_user = 0, no_group = 0, print_real = 0; char *cp, *user, *group; - unsigned long gid; + long gid; + long pwnam, grnam; int opt; cp = user = group = NULL; @@ -59,8 +59,8 @@ extern int id_main(int argc, char **argv) user = argv[optind]; if (user == NULL) { - user = xmalloc(9); - group = xmalloc(9); + user = xcalloc(9, sizeof(char)); + group = xcalloc(9, sizeof(char)); if (print_real) { my_getpwuid(user, getuid()); my_getgrgid(group, getgid()); @@ -69,19 +69,22 @@ extern int id_main(int argc, char **argv) my_getgrgid(group, getegid()); } } else { - group = xmalloc(9); + group = xcalloc(9, sizeof(char)); gid = my_getpwnamegid(user); my_getgrgid(group, gid); } + pwnam=my_getpwnam(user); + grnam=my_getgrnam(group); + if (gid == -1 || pwnam==-1 || grnam==-1) { + fatalError("%s: No such user\n", user); + } if (no_group) - printf("%lu\n", my_getpwnam(user)); + printf("%ld\n", pwnam); else if (no_user) - printf("%lu\n", my_getgrnam(group)); + printf("%ld\n", grnam); else - printf("uid=%lu(%s) gid=%lu(%s)\n", - my_getpwnam(user), user, my_getgrnam(group), group); - + printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group); return(0); } |