Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libpwdgrp


Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

Location:
branches/stable/mindi-busybox/libpwdgrp
Files:
2 deleted
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/libpwdgrp/pwd_grp.c

    r821 r1770  
     1/* vi: set sw=4 ts=4: */
    12/*  Copyright (C) 2003     Manuel Novoa III
    23 *
     
    2021#include "libbb.h"
    2122#include <features.h>
    22 #include <stdio.h>
    23 #include <stdlib.h>
    24 #include <stdint.h>
    25 #include <string.h>
    26 #include <stddef.h>
    27 #include <errno.h>
    2823#include <assert.h>
    29 #include <ctype.h>
    30 
    31 #include "shadow_.h"
    3224
    3325#ifndef _PATH_SHADOW
     
    5244/* Prototypes for internal functions. */
    5345
    54 extern int __parsepwent(void *pw, char *line);
    55 extern int __parsegrent(void *gr, char *line);
    56 extern int __parsespent(void *sp, char *line);
    57 
    58 extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
    59                        char *__restrict line_buff, size_t buflen, FILE *f);
     46static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data,
     47        char *__restrict line_buff, size_t buflen, FILE *f);
     48
     49static int bb__parsepwent(void *pw, char *line);
     50static int bb__parsegrent(void *gr, char *line);
     51#if ENABLE_USE_BB_SHADOW
     52static int bb__parsespent(void *sp, char *line);
     53#endif
     54
     55/**********************************************************************/
     56/* We avoid having big global data. */
     57
     58struct statics {
     59    /* Smaller things first */
     60    struct passwd getpwuid_resultbuf;
     61    struct group getgrgid_resultbuf;
     62    struct passwd getpwnam_resultbuf;
     63    struct group getgrnam_resultbuf;
     64
     65    char getpwuid_buffer[PWD_BUFFER_SIZE];
     66    char getgrgid_buffer[GRP_BUFFER_SIZE];
     67    char getpwnam_buffer[PWD_BUFFER_SIZE];
     68    char getgrnam_buffer[GRP_BUFFER_SIZE];
     69#if 0
     70    struct passwd fgetpwent_resultbuf;
     71    struct group fgetgrent_resultbuf;
     72    struct spwd fgetspent_resultbuf;
     73    char fgetpwent_buffer[PWD_BUFFER_SIZE];
     74    char fgetgrent_buffer[GRP_BUFFER_SIZE];
     75    char fgetspent_buffer[PWD_BUFFER_SIZE];
     76#endif
     77#if 0 //ENABLE_USE_BB_SHADOW
     78    struct spwd getspuid_resultbuf;
     79    struct spwd getspnam_resultbuf;
     80    char getspuid_buffer[PWD_BUFFER_SIZE];
     81    char getspnam_buffer[PWD_BUFFER_SIZE];
     82#endif
     83// Not converted - too small to bother
     84//pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
     85//FILE *pwf /*= NULL*/;
     86//FILE *grf /*= NULL*/;
     87//FILE *spf /*= NULL*/;
     88#if 0
     89    struct passwd getpwent_pwd;
     90    struct group getgrent_gr;
     91    char getpwent_line_buff[PWD_BUFFER_SIZE];
     92    char getgrent_line_buff[GRP_BUFFER_SIZE];
     93#endif
     94#if 0 //ENABLE_USE_BB_SHADOW
     95    struct spwd getspent_spwd;
     96    struct spwd sgetspent_spwd;
     97    char getspent_line_buff[PWD_BUFFER_SIZE];
     98    char sgetspent_line_buff[PWD_BUFFER_SIZE];
     99#endif
     100};
     101
     102static struct statics *ptr_to_statics;
     103
     104static struct statics *get_S(void)
     105{
     106    if (!ptr_to_statics)
     107        ptr_to_statics = xzalloc(sizeof(*ptr_to_statics));
     108    return ptr_to_statics;
     109}
     110
     111/* Always use in this order, get_S() must be called first */
     112#define RESULTBUF(name) &((S = get_S())->name##_resultbuf)
     113#define BUFFER(name)    (S->name##_buffer)
    60114
    61115/**********************************************************************/
     
    65119 *  ENOENT: end-of-file encountered
    66120 *  ERANGE: buflen too small
    67  *  other error values possible. See __pgsreader.
     121 *  other error values possible. See bb__pgsreader.
    68122 *
    69123 * Also, *result == resultbuf on success and NULL on failure.
     
    75129/**********************************************************************/
    76130
    77 #ifdef L_fgetpwent_r
    78 
    79131int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf,
    80132                char *__restrict buffer, size_t buflen,
     
    85137    *result = NULL;
    86138
    87     if (!(rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream))) {
     139    rv = bb__pgsreader(bb__parsepwent, resultbuf, buffer, buflen, stream);
     140    if (!rv) {
    88141        *result = resultbuf;
    89142    }
     
    91144    return rv;
    92145}
    93 
    94 #endif
    95 /**********************************************************************/
    96 #ifdef L_fgetgrent_r
    97146
    98147int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
     
    104153    *result = NULL;
    105154
    106     if (!(rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream))) {
     155    rv = bb__pgsreader(bb__parsegrent, resultbuf, buffer, buflen, stream);
     156    if (!rv) {
    107157        *result = resultbuf;
    108158    }
     
    111161}
    112162
    113 #endif
    114 /**********************************************************************/
    115 #ifdef L_fgetspent_r
    116 
     163#if ENABLE_USE_BB_SHADOW
    117164int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
    118165                char *__restrict buffer, size_t buflen,
     
    123170    *result = NULL;
    124171
    125     if (!(rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream))) {
     172    rv = bb__pgsreader(bb__parsespent, resultbuf, buffer, buflen, stream);
     173    if (!rv) {
    126174        *result = resultbuf;
    127175    }
     
    129177    return rv;
    130178}
    131 
    132 #endif
     179#endif
     180
    133181/**********************************************************************/
    134182/* For the various fget??ent funcs, return NULL on failure and a
    135183 * pointer to the appropriate struct (statically allocated) on success.
    136  */
    137 /**********************************************************************/
    138 #ifdef L_fgetpwent
    139 
     184 * TODO: audit & stop using these in bbox, they pull in static buffers */
     185/**********************************************************************/
     186
     187#if 0
    140188struct passwd *fgetpwent(FILE *stream)
    141189{
    142     static char buffer[PWD_BUFFER_SIZE];
    143     static struct passwd resultbuf;
     190    struct statics *S;
     191    struct passwd *resultbuf = RESULTBUF(fgetpwent);
     192    char *buffer = BUFFER(fgetpwent);
    144193    struct passwd *result;
    145194
    146     fgetpwent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
    147     return result;
    148 }
    149 
    150 #endif
    151 /**********************************************************************/
    152 #ifdef L_fgetgrent
     195    fgetpwent_r(stream, resultbuf, buffer, sizeof(BUFFER(fgetpwent)), &result);
     196    return result;
     197}
    153198
    154199struct group *fgetgrent(FILE *stream)
    155200{
    156     static char buffer[GRP_BUFFER_SIZE];
    157     static struct group resultbuf;
     201    struct statics *S;
     202    struct group *resultbuf = RESULTBUF(fgetgrent);
     203    char *buffer = BUFFER(fgetgrent);
    158204    struct group *result;
    159205
    160     fgetgrent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
    161     return result;
    162 }
    163 
    164 #endif
    165 /**********************************************************************/
    166 #ifdef L_fgetspent
    167 
    168 extern int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
    169                 char *__restrict buffer, size_t buflen,
    170                 struct spwd **__restrict result);
     206    fgetgrent_r(stream, resultbuf, buffer, sizeof(BUFFER(fgetgrent)), &result);
     207    return result;
     208}
     209#endif
     210
     211#if ENABLE_USE_BB_SHADOW
     212#if 0
    171213struct spwd *fgetspent(FILE *stream)
    172214{
    173     static char buffer[PWD_BUFFER_SIZE];
    174     static struct spwd resultbuf;
     215    struct statics *S;
     216    struct spwd *resultbuf = RESULTBUF(fgetspent);
     217    char *buffer = BUFFER(fgetspent);
    175218    struct spwd *result;
    176219
    177     fgetspent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
    178     return result;
    179 }
    180 
    181 #endif
    182 /**********************************************************************/
    183 #ifdef L_sgetspent_r
     220    fgetspent_r(stream, resultbuf, buffer, sizeof(BUFFER(fgetspent)), &result);
     221    return result;
     222}
     223#endif
    184224
    185225int sgetspent_r(const char *string, struct spwd *result_buf,
     
    203243    }
    204244
    205     if (!(rv = __parsespent(result_buf, buffer))) {
     245    rv = bb__parsespent(result_buf, buffer);
     246    if (!rv) {
    206247        *result = result_buf;
    207248    }
     
    210251    return rv;
    211252}
    212 
    213 #endif
    214 /**********************************************************************/
    215 
    216 #ifdef GETXXKEY_R_FUNC
    217 #error GETXXKEY_R_FUNC is already defined!
    218 #endif
    219 
    220 #ifdef L_getpwnam_r
    221 #define GETXXKEY_R_FUNC         getpwnam_r
    222 #define GETXXKEY_R_PARSER       __parsepwent
    223 #define GETXXKEY_R_ENTTYPE      struct passwd
    224 #define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->pw_name, key))
    225 #define DO_GETXXKEY_R_KEYTYPE   const char *__restrict
    226 #define DO_GETXXKEY_R_PATHNAME  _PATH_PASSWD
     253#endif
     254
     255/**********************************************************************/
     256
     257#define GETXXKEY_R_FUNC         getpwnam_r
     258#define GETXXKEY_R_PARSER       bb__parsepwent
     259#define GETXXKEY_R_ENTTYPE      struct passwd
     260#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->pw_name, key))
     261#define GETXXKEY_R_KEYTYPE      const char *__restrict
     262#define GETXXKEY_R_PATHNAME     _PATH_PASSWD
    227263#include "pwd_grp_internal.c"
    228 #endif
    229 
    230 #ifdef L_getgrnam_r
    231 #define GETXXKEY_R_FUNC         getgrnam_r
    232 #define GETXXKEY_R_PARSER       __parsegrent
    233 #define GETXXKEY_R_ENTTYPE      struct group
    234 #define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->gr_name, key))
    235 #define DO_GETXXKEY_R_KEYTYPE   const char *__restrict
    236 #define DO_GETXXKEY_R_PATHNAME  _PATH_GROUP
     264
     265#define GETXXKEY_R_FUNC         getgrnam_r
     266#define GETXXKEY_R_PARSER       bb__parsegrent
     267#define GETXXKEY_R_ENTTYPE      struct group
     268#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->gr_name, key))
     269#define GETXXKEY_R_KEYTYPE      const char *__restrict
     270#define GETXXKEY_R_PATHNAME     _PATH_GROUP
    237271#include "pwd_grp_internal.c"
    238 #endif
    239 
    240 #ifdef L_getspnam_r
    241 #define GETXXKEY_R_FUNC         getspnam_r
    242 #define GETXXKEY_R_PARSER       __parsespent
    243 #define GETXXKEY_R_ENTTYPE      struct spwd
    244 #define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->sp_namp, key))
    245 #define DO_GETXXKEY_R_KEYTYPE   const char *__restrict
    246 #define DO_GETXXKEY_R_PATHNAME  _PATH_SHADOW
     272
     273#if ENABLE_USE_BB_SHADOW
     274#define GETXXKEY_R_FUNC         getspnam_r
     275#define GETXXKEY_R_PARSER       bb__parsespent
     276#define GETXXKEY_R_ENTTYPE      struct spwd
     277#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->sp_namp, key))
     278#define GETXXKEY_R_KEYTYPE      const char *__restrict
     279#define GETXXKEY_R_PATHNAME     _PATH_SHADOW
    247280#include "pwd_grp_internal.c"
    248281#endif
    249282
    250 #ifdef L_getpwuid_r
    251 #define GETXXKEY_R_FUNC         getpwuid_r
    252 #define GETXXKEY_R_PARSER       __parsepwent
    253 #define GETXXKEY_R_ENTTYPE      struct passwd
    254 #define GETXXKEY_R_TEST(ENT)    ((ENT)->pw_uid == key)
    255 #define DO_GETXXKEY_R_KEYTYPE   uid_t
    256 #define DO_GETXXKEY_R_PATHNAME  _PATH_PASSWD
     283#define GETXXKEY_R_FUNC         getpwuid_r
     284#define GETXXKEY_R_PARSER       bb__parsepwent
     285#define GETXXKEY_R_ENTTYPE      struct passwd
     286#define GETXXKEY_R_TEST(ENT)    ((ENT)->pw_uid == key)
     287#define GETXXKEY_R_KEYTYPE      uid_t
     288#define GETXXKEY_R_PATHNAME     _PATH_PASSWD
    257289#include "pwd_grp_internal.c"
    258 #endif
    259 
    260 #ifdef L_getgrgid_r
    261 #define GETXXKEY_R_FUNC         getgrgid_r
    262 #define GETXXKEY_R_PARSER       __parsegrent
    263 #define GETXXKEY_R_ENTTYPE      struct group
    264 #define GETXXKEY_R_TEST(ENT)    ((ENT)->gr_gid == key)
    265 #define DO_GETXXKEY_R_KEYTYPE   gid_t
    266 #define DO_GETXXKEY_R_PATHNAME  _PATH_GROUP
     290
     291#define GETXXKEY_R_FUNC         getgrgid_r
     292#define GETXXKEY_R_PARSER       bb__parsegrent
     293#define GETXXKEY_R_ENTTYPE      struct group
     294#define GETXXKEY_R_TEST(ENT)    ((ENT)->gr_gid == key)
     295#define GETXXKEY_R_KEYTYPE      gid_t
     296#define GETXXKEY_R_PATHNAME     _PATH_GROUP
    267297#include "pwd_grp_internal.c"
    268 #endif
    269 
    270 /**********************************************************************/
    271 #ifdef L_getpwuid
    272 
     298
     299/**********************************************************************/
     300/* TODO: audit & stop using these in bbox, they pull in static buffers */
     301
     302/* This one has many users */
    273303struct passwd *getpwuid(uid_t uid)
    274304{
    275     static char buffer[PWD_BUFFER_SIZE];
    276     static struct passwd resultbuf;
     305    struct statics *S;
     306    struct passwd *resultbuf = RESULTBUF(getpwuid);
     307    char *buffer = BUFFER(getpwuid);
    277308    struct passwd *result;
    278309
    279     getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
    280     return result;
    281 }
    282 
    283 #endif
    284 /**********************************************************************/
    285 #ifdef L_getgrgid
    286 
     310    getpwuid_r(uid, resultbuf, buffer, sizeof(BUFFER(getpwuid)), &result);
     311    return result;
     312}
     313
     314/* This one has many users */
    287315struct group *getgrgid(gid_t gid)
    288316{
    289     static char buffer[GRP_BUFFER_SIZE];
    290     static struct group resultbuf;
     317    struct statics *S;
     318    struct group *resultbuf = RESULTBUF(getgrgid);
     319    char *buffer = BUFFER(getgrgid);
    291320    struct group *result;
    292321
    293     getgrgid_r(gid, &resultbuf, buffer, sizeof(buffer), &result);
    294     return result;
    295 }
    296 
    297 #endif
    298 /**********************************************************************/
    299 #ifdef L_getspuid_r
    300 
     322    getgrgid_r(gid, resultbuf, buffer, sizeof(BUFFER(getgrgid)), &result);
     323    return result;
     324}
     325
     326#if 0 //ENABLE_USE_BB_SHADOW
    301327/* This function is non-standard and is currently not built.  It seems
    302328 * to have been created as a reentrant version of the non-standard
    303329 * functions getspuid.  Why getspuid was added, I do not know. */
    304 
    305330int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
    306331               char *__restrict buffer, size_t buflen,
     
    313338
    314339    *result = NULL;
    315     if (!(rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp))) {
     340    rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp);
     341    if (!rv) {
    316342        rv = getspnam_r(password.pw_name, resultbuf, buffer, buflen, result);
    317343    }
     
    319345    return rv;
    320346}
    321 
    322 #endif
    323 /**********************************************************************/
    324 #ifdef L_getspuid
    325347
    326348/* This function is non-standard and is currently not built.
    327349 * Why it was added, I do not know. */
    328 
    329350struct spwd *getspuid(uid_t uid)
    330351{
    331     static char buffer[PWD_BUFFER_SIZE];
    332     static struct spwd resultbuf;
     352    struct statics *S;
     353    struct spwd *resultbuf = RESULTBUF(getspuid);
     354    char *buffer = BUFFER(getspuid);
    333355    struct spwd *result;
    334356
    335     getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
    336     return result;
    337 }
    338 
    339 #endif
    340 /**********************************************************************/
    341 #ifdef L_getpwnam
    342 
     357    getspuid_r(uid, resultbuf, buffer, sizeof(BUFFER(getspuid)), &result);
     358    return result;
     359}
     360#endif
     361
     362/* This one has many users */
    343363struct passwd *getpwnam(const char *name)
    344364{
    345     static char buffer[PWD_BUFFER_SIZE];
    346     static struct passwd resultbuf;
     365    struct statics *S;
     366    struct passwd *resultbuf = RESULTBUF(getpwnam);
     367    char *buffer = BUFFER(getpwnam);
    347368    struct passwd *result;
    348369
    349     getpwnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
    350     return result;
    351 }
    352 
    353 #endif
    354 /**********************************************************************/
    355 #ifdef L_getgrnam
    356 
     370    getpwnam_r(name, resultbuf, buffer, sizeof(BUFFER(getpwnam)), &result);
     371    return result;
     372}
     373
     374/* This one has many users */
    357375struct group *getgrnam(const char *name)
    358376{
    359     static char buffer[GRP_BUFFER_SIZE];
    360     static struct group resultbuf;
     377    struct statics *S;
     378    struct group *resultbuf = RESULTBUF(getgrnam);
     379    char *buffer = BUFFER(getgrnam);
    361380    struct group *result;
    362381
    363     getgrnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
    364     return result;
    365 }
    366 
    367 #endif
    368 /**********************************************************************/
    369 #ifdef L_getspnam
    370 
     382    getgrnam_r(name, resultbuf, buffer, sizeof(BUFFER(getgrnam)), &result);
     383    return result;
     384}
     385
     386#if 0 //ENABLE_USE_BB_SHADOW
    371387struct spwd *getspnam(const char *name)
    372388{
    373     static char buffer[PWD_BUFFER_SIZE];
    374     static struct spwd resultbuf;
     389    struct statics *S;
     390    struct spwd *resultbuf = RESULTBUF(getspnam);
     391    char *buffer = BUFFER(getspnam);
    375392    struct spwd *result;
    376393
    377     getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
    378     return result;
    379 }
    380 
    381 #endif
    382 /**********************************************************************/
    383 #ifdef L_getpw
    384 
     394    getspnam_r(name, resultbuf, buffer, sizeof(BUFFER(getspnam)), &result);
     395    return result;
     396}
     397#endif
     398
     399/* This one doesn't use static buffers */
    385400int getpw(uid_t uid, char *buf)
    386401{
     
    390405
    391406    if (!buf) {
    392         errno=EINVAL;
     407        errno = EINVAL;
    393408    } else if (!getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result)) {
    394409        if (sprintf(buf, "%s:%s:%lu:%lu:%s:%s:%s\n",
     
    406421}
    407422
    408 #endif
    409 /**********************************************************************/
    410 
    411 #if defined(L_getpwent_r) || defined(L_getgrent_r) || defined(L_getspent_r)
     423/**********************************************************************/
     424
     425/* FIXME: we don't have such CONFIG_xx - ?! */
     426
    412427#if defined CONFIG_USE_BB_THREADSAFE_SHADOW && defined PTHREAD_MUTEX_INITIALIZER
    413428static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
     
    418433# define UNLOCK     ((void) 0)
    419434#endif
    420 #endif
    421 
    422 #ifdef L_getpwent_r
     435
    423436static FILE *pwf /*= NULL*/;
    424437void setpwent(void)
     
    452465
    453466    if (!pwf) {
    454         if (!(pwf = fopen(_PATH_PASSWD, "r"))) {
     467        pwf = fopen(_PATH_PASSWD, "r");
     468        if (!pwf) {
    455469            rv = errno;
    456470            goto ERR;
     
    458472    }
    459473
    460     if (!(rv = __pgsreader(__parsepwent, resultbuf,
    461                            buffer, buflen, pwf))) {
     474    rv = bb__pgsreader(bb__parsepwent, resultbuf, buffer, buflen, pwf);
     475    if (!rv) {
    462476        *result = resultbuf;
    463477    }
     
    467481    return rv;
    468482}
    469 
    470 #endif
    471 /**********************************************************************/
    472 #ifdef L_getgrent_r
    473483
    474484static FILE *grf /*= NULL*/;
     
    502512
    503513    if (!grf) {
    504         if (!(grf = fopen(_PATH_GROUP, "r"))) {
     514        grf = fopen(_PATH_GROUP, "r");
     515        if (!grf) {
    505516            rv = errno;
    506517            goto ERR;
     
    508519    }
    509520
    510     if (!(rv = __pgsreader(__parsegrent, resultbuf,
    511                            buffer, buflen, grf))) {
     521    rv = bb__pgsreader(bb__parsegrent, resultbuf, buffer, buflen, grf);
     522    if (!rv) {
    512523        *result = resultbuf;
    513524    }
     
    518529}
    519530
    520 #endif
    521 /**********************************************************************/
    522 #ifdef L_getspent_r
    523 
     531#if ENABLE_USE_BB_SHADOW
    524532static FILE *spf /*= NULL*/;
    525533void setspent(void)
     
    551559
    552560    if (!spf) {
    553         if (!(spf = fopen(_PATH_SHADOW, "r"))) {
     561        spf = fopen(_PATH_SHADOW, "r");
     562        if (!spf) {
    554563            rv = errno;
    555564            goto ERR;
     
    557566    }
    558567
    559     if (!(rv = __pgsreader(__parsespent, resultbuf,
    560                            buffer, buflen, spf))) {
     568    rv = bb__pgsreader(bb__parsespent, resultbuf, buffer, buflen, spf);
     569    if (!rv) {
    561570        *result = resultbuf;
    562571    }
     
    566575    return rv;
    567576}
    568 
    569 #endif
    570 /**********************************************************************/
    571 #ifdef L_getpwent
    572 
     577#endif
     578
     579#if 0
    573580struct passwd *getpwent(void)
    574581{
     
    581588}
    582589
    583 #endif
    584 /**********************************************************************/
    585 #ifdef L_getgrent
    586 
    587590struct group *getgrent(void)
    588591{
     
    594597    return result;
    595598}
    596 
    597 #endif
    598 /**********************************************************************/
    599 #ifdef L_getspent
    600 
     599#endif
     600
     601#if 0 //ENABLE_USE_BB_SHADOW
    601602struct spwd *getspent(void)
    602603{
     
    609610}
    610611
    611 #endif
    612 /**********************************************************************/
    613 #ifdef L_sgetspent
    614 
    615612struct spwd *sgetspent(const char *string)
    616613{
     
    622619    return result;
    623620}
    624 
    625 #endif
    626 /**********************************************************************/
    627 #ifdef L_initgroups
     621#endif
    628622
    629623int initgroups(const char *user, gid_t gid)
     
    639633
    640634    /* We alloc space for 8 gids at a time. */
    641     if (((group_list = (gid_t *) malloc(8*sizeof(gid_t *))) != NULL)
    642         && ((grfile = fopen(_PATH_GROUP, "r")) != NULL)
    643         ) {
    644 
     635    group_list = (gid_t *) malloc(8*sizeof(gid_t *));
     636    if (group_list
     637     && ((grfile = fopen(_PATH_GROUP, "r")) != NULL)
     638    ) {
    645639        *group_list = gid;
    646640        num_groups = 1;
    647641
    648         while (!__pgsreader(__parsegrent, &group, buff, sizeof(buff), grfile)) {
     642        while (!bb__pgsreader(bb__parsegrent, &group, buff, sizeof(buff), grfile)) {
    649643            assert(group.gr_mem); /* Must have at least a NULL terminator. */
    650644            if (group.gr_gid != gid) {
    651                 for (m=group.gr_mem ; *m ; m++) {
     645                for (m = group.gr_mem; *m; m++) {
    652646                    if (!strcmp(*m, user)) {
    653647                        if (!(num_groups & 7)) {
     
    679673}
    680674
    681 #endif
    682 /**********************************************************************/
    683 #ifdef L_putpwent
    684 
    685675int putpwent(const struct passwd *__restrict p, FILE *__restrict f)
    686676{
     
    704694}
    705695
    706 #endif
    707 /**********************************************************************/
    708 #ifdef L_putgrent
    709 
    710696int putgrent(const struct group *__restrict p, FILE *__restrict f)
    711697{
    712     static const char format[] = ",%s";
     698    static const char format[] ALIGN1 = ",%s";
     699
    713700    char **m;
    714701    const char *fmt;
     
    749736}
    750737
    751 #endif
    752 /**********************************************************************/
    753 #ifdef L_putspent
    754 
    755 static const unsigned char _sp_off[] = {
    756     offsetof(struct spwd, sp_lstchg),   /* 2 - not a char ptr */
    757     offsetof(struct spwd, sp_min),      /* 3 - not a char ptr */
    758     offsetof(struct spwd, sp_max),      /* 4 - not a char ptr */
    759     offsetof(struct spwd, sp_warn),     /* 5 - not a char ptr */
    760     offsetof(struct spwd, sp_inact),    /* 6 - not a char ptr */
    761     offsetof(struct spwd, sp_expire),   /* 7 - not a char ptr */
     738#if ENABLE_USE_BB_SHADOW
     739static const unsigned char _sp_off[] ALIGN1 = {
     740    offsetof(struct spwd, sp_lstchg),       /* 2 - not a char ptr */
     741    offsetof(struct spwd, sp_min),          /* 3 - not a char ptr */
     742    offsetof(struct spwd, sp_max),          /* 4 - not a char ptr */
     743    offsetof(struct spwd, sp_warn),         /* 5 - not a char ptr */
     744    offsetof(struct spwd, sp_inact),        /* 6 - not a char ptr */
     745    offsetof(struct spwd, sp_expire)        /* 7 - not a char ptr */
    762746};
    763747
    764748int putspent(const struct spwd *p, FILE *stream)
    765749{
    766     static const char ld_format[] = "%ld:";
     750    static const char ld_format[] ALIGN1 = "%ld:";
     751
    767752    const char *f;
    768     long int x;
     753    long x;
    769754    int i;
    770755    int rv = -1;
     
    773758    if (fprintf(stream, "%s:%s:", p->sp_namp,
    774759                (p->sp_pwdp ? p->sp_pwdp : "")) < 0
    775         ) {
     760    ) {
    776761        goto DO_UNLOCK;
    777762    }
    778763
    779     for (i=0 ; i < sizeof(_sp_off) ; i++) {
     764    for (i = 0; i < sizeof(_sp_off); i++) {
    780765        f = ld_format;
    781         if ((x = *(const long int *)(((const char *) p) + _sp_off[i])) == -1) {
     766        x = *(const long *)(((const char *) p) + _sp_off[i]);
     767        if (x == -1) {
    782768            f += 3;
    783769        }
     
    798784    return rv;
    799785}
    800 
    801 #endif
    802 /**********************************************************************/
    803 /* Internal uClibc functions.                    */
    804 /**********************************************************************/
    805 #ifdef L___parsepwent
    806 
    807 static const unsigned char pw_off[] = {
    808     offsetof(struct passwd, pw_name),   /* 0 */
    809     offsetof(struct passwd, pw_passwd), /* 1 */
    810     offsetof(struct passwd, pw_uid),    /* 2 - not a char ptr */
    811     offsetof(struct passwd, pw_gid),    /* 3 - not a char ptr */
    812     offsetof(struct passwd, pw_gecos),  /* 4 */
    813     offsetof(struct passwd, pw_dir),    /* 5 */
    814     offsetof(struct passwd, pw_shell)   /* 6 */
     786#endif
     787
     788/**********************************************************************/
     789/* Internal uClibc functions.                                         */
     790/**********************************************************************/
     791
     792static const unsigned char pw_off[] ALIGN1 = {
     793    offsetof(struct passwd, pw_name),       /* 0 */
     794    offsetof(struct passwd, pw_passwd),     /* 1 */
     795    offsetof(struct passwd, pw_uid),        /* 2 - not a char ptr */
     796    offsetof(struct passwd, pw_gid),        /* 3 - not a char ptr */
     797    offsetof(struct passwd, pw_gecos),      /* 4 */
     798    offsetof(struct passwd, pw_dir),        /* 5 */
     799    offsetof(struct passwd, pw_shell)       /* 6 */
    815800};
    816801
    817 int __parsepwent(void *data, char *line)
     802static int bb__parsepwent(void *data, char *line)
    818803{
    819804    char *endptr;
     
    833818             * ':' seperators after the gid field if all remaining
    834819             * entries are empty.  We require all separators. */
    835             if (!(line = strchr(line, ':'))) {
     820            line = strchr(line, ':');
     821            if (!line) {
    836822                break;
    837823            }
     
    860846}
    861847
    862 #endif
    863 /**********************************************************************/
    864 #ifdef L___parsegrent
    865 
    866 static const unsigned char gr_off[] = {
    867     offsetof(struct group, gr_name),    /* 0 */
    868     offsetof(struct group, gr_passwd),  /* 1 */
    869     offsetof(struct group, gr_gid)      /* 2 - not a char ptr */
     848/**********************************************************************/
     849
     850static const unsigned char gr_off[] ALIGN1 = {
     851    offsetof(struct group, gr_name),        /* 0 */
     852    offsetof(struct group, gr_passwd),      /* 1 */
     853    offsetof(struct group, gr_gid)          /* 2 - not a char ptr */
    870854};
    871855
    872 int __parsegrent(void *data, char *line)
     856static int bb__parsegrent(void *data, char *line)
    873857{
    874858    char *endptr;
     
    885869        if (i < 2) {
    886870            *((char **) p) = line;
    887             if (!(line = strchr(line, ':'))) {
     871            line = strchr(line, ':');
     872            if (!line) {
    888873                break;
    889874            }
     
    958943}
    959944
    960 #endif
    961 /**********************************************************************/
    962 #ifdef L___parsespent
    963 
    964 static const unsigned char sp_off[] = {
    965     offsetof(struct spwd, sp_namp),     /* 0 */
    966     offsetof(struct spwd, sp_pwdp),     /* 1 */
    967     offsetof(struct spwd, sp_lstchg),   /* 2 - not a char ptr */
    968     offsetof(struct spwd, sp_min),      /* 3 - not a char ptr */
    969     offsetof(struct spwd, sp_max),      /* 4 - not a char ptr */
    970     offsetof(struct spwd, sp_warn),     /* 5 - not a char ptr */
    971     offsetof(struct spwd, sp_inact),    /* 6 - not a char ptr */
    972     offsetof(struct spwd, sp_expire),   /* 7 - not a char ptr */
    973     offsetof(struct spwd, sp_flag)      /* 8 - not a char ptr */
     945/**********************************************************************/
     946
     947#if ENABLE_USE_BB_SHADOW
     948static const unsigned char sp_off[] ALIGN1 = {
     949    offsetof(struct spwd, sp_namp),         /* 0 */
     950    offsetof(struct spwd, sp_pwdp),         /* 1 */
     951    offsetof(struct spwd, sp_lstchg),       /* 2 - not a char ptr */
     952    offsetof(struct spwd, sp_min),          /* 3 - not a char ptr */
     953    offsetof(struct spwd, sp_max),          /* 4 - not a char ptr */
     954    offsetof(struct spwd, sp_warn),         /* 5 - not a char ptr */
     955    offsetof(struct spwd, sp_inact),        /* 6 - not a char ptr */
     956    offsetof(struct spwd, sp_expire),       /* 7 - not a char ptr */
     957    offsetof(struct spwd, sp_flag)          /* 8 - not a char ptr */
    974958};
    975959
    976 int __parsespent(void *data, char * line)
     960static int bb__parsespent(void *data, char * line)
    977961{
    978962    char *endptr;
     
    985969        if (i < 2) {
    986970            *((char **) p) = line;
    987             if (!(line = strchr(line, ':'))) {
     971            line = strchr(line, ':');
     972            if (!line) {
    988973                break;
    989974            }
    990975        } else {
    991 #if 0
    992             if (i==5) {         /* Support for old format. */
    993                 while (isspace(*line)) ++line; /* glibc eats space here. */
    994                 if (!*line) {
    995                     ((struct spwd *) data)->sp_warn = -1;
    996                     ((struct spwd *) data)->sp_inact = -1;
    997                     ((struct spwd *) data)->sp_expire = -1;
    998                     ((struct spwd *) data)->sp_flag = ~0UL;
    999                     return 0;
    1000                 }
    1001             }
    1002 #endif
    1003 
    1004976            *((long *) p) = (long) strtoul(line, &endptr, 10);
    1005977
     
    10291001    return EINVAL;
    10301002}
    1031 
    1032 #endif
    1033 /**********************************************************************/
    1034 #ifdef L___pgsreader
     1003#endif
     1004
     1005/**********************************************************************/
    10351006
    10361007/* Reads until if EOF, or until if finds a line which fits in the buffer
     
    10401011 */
    10411012
    1042 int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
     1013static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data,
    10431014                char *__restrict line_buff, size_t buflen, FILE *f)
    10441015{
     
    10481019
    10491020    if (buflen < PWD_BUFFER_SIZE) {
    1050         errno=rv;
     1021        errno = rv;
    10511022    } else {
    10521023        skip = 0;
     
    10781049             * whitespace. */
    10791050            if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) {
    1080                 if (__parserfunc == __parsegrent) { /* Do evil group hack. */
     1051                if (parserfunc == bb__parsegrent) { /* Do evil group hack. */
    10811052                    /* The group entry parsing function needs to know where
    10821053                     * the end of the buffer is so that it can construct the
     
    10851056                }
    10861057
    1087                 if (!__parserfunc(data, line_buff)) {
     1058                if (!parserfunc(data, line_buff)) {
    10881059                    rv = 0;
    10891060                    break;
     
    10961067    return rv;
    10971068}
    1098 
    1099 #endif
    1100 /**********************************************************************/
  • branches/stable/mindi-busybox/libpwdgrp/pwd_grp_internal.c

    r821 r1770  
     1/* vi: set sw=4 ts=4: */
    12/*  Copyright (C) 2003     Manuel Novoa III
    23 *
     
    1819 */
    1920
    20 #include <features.h>
    21 #include <stdio.h>
    22 #include <stdlib.h>
    23 #include <stdint.h>
    24 #include <string.h>
    25 #include <stddef.h>
    26 #include <errno.h>
    27 #include <assert.h>
    28 #include <ctype.h>
    29 
    30 #include "pwd_.h"
    31 #include "grp_.h"
    32 #include "shadow_.h"
    33 #include "libbb.h"
    34 
    35 #ifndef _PATH_SHADOW
    36 #define _PATH_SHADOW    "/etc/shadow"
    37 #endif
    38 #ifndef _PATH_PASSWD
    39 #define _PATH_PASSWD    "/etc/passwd"
    40 #endif
    41 #ifndef _PATH_GROUP
    42 #define _PATH_GROUP "/etc/group"
    43 #endif
    44 
    45 /**********************************************************************/
    46 /* Sizes for statically allocated buffers. */
    47 
    48 /* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
    49  * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
    50 #define PWD_BUFFER_SIZE 256
    51 #define GRP_BUFFER_SIZE 256
    52 
    53 /**********************************************************************/
    54 /* Prototypes for internal functions. */
    55 
    56 extern int __parsepwent(void *pw, char *line);
    57 extern int __parsegrent(void *gr, char *line);
    58 extern int __parsespent(void *sp, char *line);
    59 
    60 extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
    61                        char *__restrict line_buff, size_t buflen, FILE *f);
    62 
    63 
    6421#ifndef GETXXKEY_R_FUNC
    6522#error GETXXKEY_R_FUNC is not defined!
    6623#endif
    67 /**********************************************************************/
    68 #ifdef GETXXKEY_R_FUNC
    6924
    70 int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
    71                     GETXXKEY_R_ENTTYPE *__restrict resultbuf,
    72                     char *__restrict buffer, size_t buflen,
    73                     GETXXKEY_R_ENTTYPE **__restrict result)
     25int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key,
     26                GETXXKEY_R_ENTTYPE *__restrict resultbuf,
     27                char *__restrict buffer, size_t buflen,
     28                GETXXKEY_R_ENTTYPE **__restrict result)
    7429{
    7530    FILE *stream;
     
    7833    *result = NULL;
    7934
    80     if (!(stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"))) {
    81         rv = errno;
    82     } else {
    83         do {
    84             if (!(rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf,
    85                                    buffer, buflen, stream))
    86                 ) {
    87                 if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
    88                     *result = resultbuf;
    89                     break;
    90                 }
    91             } else {
    92                 if (rv == ENOENT) { /* end-of-file encountered. */
    93                     rv = 0;
    94                 }
     35    stream = fopen(GETXXKEY_R_PATHNAME, "r");
     36    if (!stream)
     37        return errno;
     38    while (1) {
     39        rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
     40        if (!rv) {
     41            if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
     42                *result = resultbuf;
    9543                break;
    9644            }
    97         } while (1);
    98         fclose(stream);
     45        } else {
     46            if (rv == ENOENT) { /* end-of-file encountered. */
     47                rv = 0;
     48            }
     49            break;
     50        }
    9951    }
     52    fclose(stream);
    10053
    10154    return rv;
    10255}
    10356
    104 #endif
    105 /**********************************************************************/
    10657#undef GETXXKEY_R_FUNC
    10758#undef GETXXKEY_R_PARSER
    10859#undef GETXXKEY_R_ENTTYPE
    10960#undef GETXXKEY_R_TEST
    110 #undef DO_GETXXKEY_R_KEYTYPE
    111 #undef DO_GETXXKEY_R_PATHNAME
    112 
     61#undef GETXXKEY_R_KEYTYPE
     62#undef GETXXKEY_R_PATHNAME
Note: See TracChangeset for help on using the changeset viewer.