hush/libbb/bb_pwd.c
Tito Ragusa 1da09cfacf libpwdgrp: rewritten to use malloced implementation
This removed buffer size limitations.

function                                             old     new   delta
convert_to_struct                                      -     269    +269
getXXnam_r                                             -     204    +204
parse_common                                           -     185    +185
getXXnam                                               -     164    +164
tokenize                                               -     126    +126
bb_internal_getpwent_r                               102     167     +65
get_S                                                 30      88     +58
getgrouplist_internal                                195     240     +45
const_sp_db                                            -      20     +20
const_pw_db                                            -      20     +20
const_gr_db                                            -      20     +20
bb_internal_endpwent                                  27      36      +9
bb_internal_endgrent                                  27      36      +9
decode_one_format                                    726     734      +8
bb_internal_setpwent                                  17      24      +7
volume_id_probe_iso9660                              319     322      +3
scriptreplay_main                                    204     207      +3
mkfs_minix_main                                     2684    2687      +3
id_main                                              478     480      +2
hash_find                                            233     235      +2
pstree_main                                          321     322      +1
gr_off                                                 3       4      +1
expand_one_var                                      1579    1578      -1
pwf                                                    4       -      -4
grf                                                    4       -      -4
pack_gzip                                           1787    1780      -7
addattr32                                             67      56     -11
buffer_fill_and_print                                191     178     -13
dpkg_main                                           2944    2927     -17
bb_internal_setgrent                                  17       -     -17
bb_internal_getpwuid                                  38      19     -19
bb_internal_getgrgid                                  44      19     -25
bb_internal_getpwnam                                  38      11     -27
bb_internal_getgrnam                                  44      14     -30
bb_internal_fgetpwent_r                               51       -     -51
bb_internal_fgetgrent_r                               51       -     -51
bb_internal_getspnam_r                               121      42     -79
bb_internal_getpwnam_r                               121      39     -82
bb_internal_getgrent_r                               102       -    -102
bb__parsepwent                                       110       -    -110
bb_internal_getpwuid_r                               113       -    -113
bb_internal_getgrgid_r                               113       -    -113
bb__parsespent                                       120       -    -120
bb_internal_getgrnam_r                               121       -    -121
bb__pgsreader                                        213       -    -213
bb__parsegrent                                       226       -    -226
------------------------------------------------------------------------------
(add/remove: 8/13 grow/shrink: 14/11 up/down: 1224/-1556)    Total: -332 bytes
   text	   data	    bss	    dec	    hex	filename
 923471	    928	  17684	 942083	  e6003	busybox_old
 923167	    928	  17676	 941771	  e5ecb	busybox_unstripped

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-02 21:37:59 +01:00

113 lines
2.1 KiB
C

/* vi: set sw=4 ts=4: */
/*
* password utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
* Copyright (C) 2008 by Tito Ragusa <farmatito@tiscali.it>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
/* TODO: maybe change API to return malloced data?
* This will allow to stop using libc functions returning
* pointers to static data (getpwuid)
*/
struct passwd* FAST_FUNC xgetpwnam(const char *name)
{
struct passwd *pw = getpwnam(name);
if (!pw)
bb_error_msg_and_die("unknown user %s", name);
return pw;
}
struct group* FAST_FUNC xgetgrnam(const char *name)
{
struct group *gr = getgrnam(name);
if (!gr)
bb_error_msg_and_die("unknown group %s", name);
return gr;
}
struct passwd* FAST_FUNC xgetpwuid(uid_t uid)
{
struct passwd *pw = getpwuid(uid);
if (!pw)
bb_error_msg_and_die("unknown uid %u", (unsigned)uid);
return pw;
}
struct group* FAST_FUNC xgetgrgid(gid_t gid)
{
struct group *gr = getgrgid(gid);
if (!gr)
bb_error_msg_and_die("unknown gid %u", (unsigned)gid);
return gr;
}
char* FAST_FUNC xuid2uname(uid_t uid)
{
struct passwd *pw = xgetpwuid(uid);
return pw->pw_name;
}
char* FAST_FUNC xgid2group(gid_t gid)
{
struct group *gr = xgetgrgid(gid);
return gr->gr_name;
}
char* FAST_FUNC uid2uname(uid_t uid)
{
struct passwd *pw = getpwuid(uid);
return (pw) ? pw->pw_name : NULL;
}
char* FAST_FUNC gid2group(gid_t gid)
{
struct group *gr = getgrgid(gid);
return (gr) ? gr->gr_name : NULL;
}
char* FAST_FUNC uid2uname_utoa(uid_t uid)
{
char *name = uid2uname(uid);
return (name) ? name : utoa(uid);
}
char* FAST_FUNC gid2group_utoa(gid_t gid)
{
char *name = gid2group(gid);
return (name) ? name : utoa(gid);
}
long FAST_FUNC xuname2uid(const char *name)
{
struct passwd *myuser;
myuser = xgetpwnam(name);
return myuser->pw_uid;
}
long FAST_FUNC xgroup2gid(const char *name)
{
struct group *mygroup;
mygroup = xgetgrnam(name);
return mygroup->gr_gid;
}
unsigned long FAST_FUNC get_ug_id(const char *s,
long FAST_FUNC (*xname2id)(const char *))
{
unsigned long r;
r = bb_strtoul(s, NULL, 10);
if (errno)
return xname2id(s);
return r;
}