aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-07-28 16:22:51 +0000
committerEric Andersen <andersen@codepoet.org>2000-07-28 16:22:51 +0000
commit6150df320a8aa825d88d6382c51017f362f2aabe (patch)
treeac57f92c33e64d0914dd18f40e40b91cd13f4483
parentd5704686b14b9cd5ae588148269cad9d7f3f1e63 (diff)
downloadbusybox-6150df320a8aa825d88d6382c51017f362f2aabe.tar.gz
Some cleanups, based on a patch from Ken Chalmers
-Erik
-rw-r--r--coreutils/id.c23
-rw-r--r--id.c23
2 files changed, 26 insertions, 20 deletions
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 <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);
}
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 <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);
}