diff --git a/coreutils/id.c b/coreutils/id.c index 6af677404..ce5db52f0 100644 --- a/coreutils/id.c +++ b/coreutils/id.c @@ -2,7 +2,6 @@ /* * Mini id implementation for busybox * - * * Copyright (C) 2000 by Randolph Chung * * 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); } diff --git a/id.c b/id.c index 6af677404..ce5db52f0 100644 --- a/id.c +++ b/id.c @@ -2,7 +2,6 @@ /* * Mini id implementation for busybox * - * * Copyright (C) 2000 by Randolph Chung * * 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); }