aboutsummaryrefslogtreecommitdiff
path: root/libpwdgrp
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-05 10:17:08 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-05 10:17:08 +0000
commit7d219aab70e6951ab82c27c202cac05016696723 (patch)
tree4c0679bfa391f71aee9b51505a5d3dc8f60a0cf7 /libpwdgrp
parent8f8f268cfdecb4cabeb2e649a73afc7a485aeff5 (diff)
downloadbusybox-w32-7d219aab70e6951ab82c27c202cac05016696723.tar.gz
busybox-w32-7d219aab70e6951ab82c27c202cac05016696723.tar.bz2
busybox-w32-7d219aab70e6951ab82c27c202cac05016696723.zip
build system overhaul
Diffstat (limited to 'libpwdgrp')
-rw-r--r--libpwdgrp/Kbuild7
-rw-r--r--libpwdgrp/Makefile23
-rw-r--r--libpwdgrp/Makefile.in51
-rw-r--r--libpwdgrp/pwd_grp.c131
-rw-r--r--libpwdgrp/pwd_grp_internal.c87
5 files changed, 31 insertions, 268 deletions
diff --git a/libpwdgrp/Kbuild b/libpwdgrp/Kbuild
new file mode 100644
index 000000000..36a6ce393
--- /dev/null
+++ b/libpwdgrp/Kbuild
@@ -0,0 +1,7 @@
1# Makefile for busybox
2#
3# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
4#
5# Licensed under the GPL v2, see the file LICENSE in this tarball.
6
7lib-y:=pwd_grp.o
diff --git a/libpwdgrp/Makefile b/libpwdgrp/Makefile
deleted file mode 100644
index 630a7688f..000000000
--- a/libpwdgrp/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
1# Makefile for busybox
2#
3# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
4#
5# Licensed under the GPL v2, see the file LICENSE in this tarball.
6
7ifndef top_srcdir
8top_srcdir=..
9endif
10ifndef top_builddir
11top_builddir=..
12endif
13srcdir=$(top_srcdir)/libpwgrp
14LIBPWDGRP_DIR:=./
15include $(top_srcdir)/Rules.mak
16include $(top_builddir)/.config
17include Makefile.in
18all: $(libraries-y)
19-include $(top_builddir)/.depend
20
21clean:
22 rm -f *.o *.a $(AR_TARGET)
23
diff --git a/libpwdgrp/Makefile.in b/libpwdgrp/Makefile.in
deleted file mode 100644
index 2511d34ef..000000000
--- a/libpwdgrp/Makefile.in
+++ /dev/null
@@ -1,51 +0,0 @@
1# Makefile for busybox
2#
3# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
4#
5# Licensed under the GPL v2, see the file LICENSE in this tarball.
6
7LIBPWDGRP_AR:=libpwdgrp.a
8ifndef $(LIBPWDGRP_DIR)
9LIBPWDGRP_DIR:=$(top_builddir)/libpwdgrp
10endif
11srcdir=$(top_srcdir)/libpwdgrp
12
13LIBPWDGRP-obj:=$(LIBPWDGRP_DIR)/$(LIBPWDGRP_AR)
14
15libraries-y+=$(LIBPWDGRP_DIR)/$(LIBPWDGRP_AR)
16
17LIBPWDGRP_MSRC0:=$(srcdir)/pwd_grp.c
18LIBPWDGRP_MOBJ0-$(CONFIG_USE_BB_PWD_GRP):= fgetpwent_r.o fgetgrent_r.o \
19 fgetpwent.o fgetgrent.o getpwnam_r.o getgrnam_r.o getpwuid_r.o \
20 getgrgid_r.o getpwuid.o getgrgid.o getpwnam.o getgrnam.o getpw.o \
21 getpwent_r.o getgrent_r.o getpwent.o getgrent.o \
22 initgroups.o putpwent.o putgrent.o
23LIBPWDGRP_MOBJS0=$(patsubst %,$(LIBPWDGRP_DIR)/%, $(LIBPWDGRP_MOBJ0-y))
24
25LIBPWDGRP_MSRC1:=$(srcdir)/pwd_grp.c
26LIBPWDGRP_MOBJ1-$(CONFIG_USE_BB_PWD_GRP):= __parsepwent.o __parsegrent.o \
27 __pgsreader.o fgetspent_r.o fgetspent.o sgetspent_r.o getspnam_r.o \
28 getspnam.o getspent_r.o getspent.o sgetspent.o \
29 putspent.o __parsespent.o # getspuid_r.o getspuid.o
30LIBPWDGRP_MOBJS1=$(patsubst %,$(LIBPWDGRP_DIR)/%, $(LIBPWDGRP_MOBJ1-y))
31
32LIBPWDGRP_DEFINE0-y:=$(patsubst %,-DL_%,$(subst .o,,$(notdir $(LIBPWDGRP_MOBJS0))))
33LIBPWDGRP_DEFINE1-y:=$(patsubst %,-DL_%,$(subst .o,,$(notdir $(LIBPWDGRP_MOBJS1))))
34
35LIBPWDGRP_SRC-y:=$(LIBPWDGRP_MSRC0)
36
37LIBRARY_SRC-y+=$(LIBPWDGRP_SRC-y)
38LIBRARY_SRC-a+=$(LIBPWDGRP_SRC-y)
39
40LIBRARY_DEFINE-y+=$(LIBPWDGRP_DEFINE0-y) $(LIBPWDGRP_DEFINE1-y)
41LIBRARY_DEFINE-a+=$(LIBPWDGRP_DEFINE0-y) $(LIBPWDGRP_DEFINE1-y)
42
43
44$(LIBPWDGRP_DIR)/$(LIBPWDGRP_AR): $(LIBPWDGRP_MOBJS0) $(LIBPWDGRP_MOBJS1)
45 $(do_ar)
46
47$(LIBPWDGRP_MOBJS0): $(LIBPWDGRP_MSRC0)
48 $(compile.c) -DL_$(notdir $*)
49
50$(LIBPWDGRP_MOBJS1): $(LIBPWDGRP_MSRC1)
51 $(compile.c) -DL_$(notdir $*)
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c
index 132ec60be..ac65d4c5b 100644
--- a/libpwdgrp/pwd_grp.c
+++ b/libpwdgrp/pwd_grp.c
@@ -29,8 +29,6 @@
29#include <assert.h> 29#include <assert.h>
30#include <ctype.h> 30#include <ctype.h>
31 31
32#include "shadow_.h"
33
34#ifndef _PATH_SHADOW 32#ifndef _PATH_SHADOW
35#define _PATH_SHADOW "/etc/shadow" 33#define _PATH_SHADOW "/etc/shadow"
36#endif 34#endif
@@ -57,7 +55,7 @@ extern int __parsegrent(void *gr, char *line);
57extern int __parsespent(void *sp, char *line); 55extern int __parsespent(void *sp, char *line);
58 56
59extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, 57extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
60 char *__restrict line_buff, size_t buflen, FILE *f); 58 char *__restrict line_buff, size_t buflen, FILE *f);
61 59
62/**********************************************************************/ 60/**********************************************************************/
63/* For the various fget??ent_r funcs, return 61/* For the various fget??ent_r funcs, return
@@ -75,8 +73,6 @@ extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
75 */ 73 */
76/**********************************************************************/ 74/**********************************************************************/
77 75
78#ifdef L_fgetpwent_r
79
80int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf, 76int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf,
81 char *__restrict buffer, size_t buflen, 77 char *__restrict buffer, size_t buflen,
82 struct passwd **__restrict result) 78 struct passwd **__restrict result)
@@ -92,10 +88,6 @@ int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf,
92 return rv; 88 return rv;
93} 89}
94 90
95#endif
96/**********************************************************************/
97#ifdef L_fgetgrent_r
98
99int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf, 91int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
100 char *__restrict buffer, size_t buflen, 92 char *__restrict buffer, size_t buflen,
101 struct group **__restrict result) 93 struct group **__restrict result)
@@ -111,10 +103,6 @@ int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
111 return rv; 103 return rv;
112} 104}
113 105
114#endif
115/**********************************************************************/
116#ifdef L_fgetspent_r
117
118int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, 106int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
119 char *__restrict buffer, size_t buflen, 107 char *__restrict buffer, size_t buflen,
120 struct spwd **__restrict result) 108 struct spwd **__restrict result)
@@ -130,13 +118,11 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
130 return rv; 118 return rv;
131} 119}
132 120
133#endif
134/**********************************************************************/ 121/**********************************************************************/
135/* For the various fget??ent funcs, return NULL on failure and a 122/* For the various fget??ent funcs, return NULL on failure and a
136 * pointer to the appropriate struct (statically allocated) on success. 123 * pointer to the appropriate struct (statically allocated) on success.
137 */ 124 */
138/**********************************************************************/ 125/**********************************************************************/
139#ifdef L_fgetpwent
140 126
141struct passwd *fgetpwent(FILE *stream) 127struct passwd *fgetpwent(FILE *stream)
142{ 128{
@@ -148,10 +134,6 @@ struct passwd *fgetpwent(FILE *stream)
148 return result; 134 return result;
149} 135}
150 136
151#endif
152/**********************************************************************/
153#ifdef L_fgetgrent
154
155struct group *fgetgrent(FILE *stream) 137struct group *fgetgrent(FILE *stream)
156{ 138{
157 static char buffer[GRP_BUFFER_SIZE]; 139 static char buffer[GRP_BUFFER_SIZE];
@@ -162,10 +144,6 @@ struct group *fgetgrent(FILE *stream)
162 return result; 144 return result;
163} 145}
164 146
165#endif
166/**********************************************************************/
167#ifdef L_fgetspent
168
169extern int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, 147extern int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
170 char *__restrict buffer, size_t buflen, 148 char *__restrict buffer, size_t buflen,
171 struct spwd **__restrict result); 149 struct spwd **__restrict result);
@@ -179,10 +157,6 @@ struct spwd *fgetspent(FILE *stream)
179 return result; 157 return result;
180} 158}
181 159
182#endif
183/**********************************************************************/
184#ifdef L_sgetspent_r
185
186int sgetspent_r(const char *string, struct spwd *result_buf, 160int sgetspent_r(const char *string, struct spwd *result_buf,
187 char *buffer, size_t buflen, struct spwd **result) 161 char *buffer, size_t buflen, struct spwd **result)
188{ 162{
@@ -211,65 +185,53 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
211 return rv; 185 return rv;
212} 186}
213 187
214#endif
215/**********************************************************************/ 188/**********************************************************************/
216 189
217#ifdef GETXXKEY_R_FUNC 190#ifdef GETXXKEY_R_FUNC
218#error GETXXKEY_R_FUNC is already defined! 191#error GETXXKEY_R_FUNC is already defined!
219#endif 192#endif
220 193
221#ifdef L_getpwnam_r 194#define GETXXKEY_R_FUNC getpwnam_R
222#define GETXXKEY_R_FUNC getpwnam_r
223#define GETXXKEY_R_PARSER __parsepwent 195#define GETXXKEY_R_PARSER __parsepwent
224#define GETXXKEY_R_ENTTYPE struct passwd 196#define GETXXKEY_R_ENTTYPE struct passwd
225#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key)) 197#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
226#define DO_GETXXKEY_R_KEYTYPE const char *__restrict 198#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
227#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD 199#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
228#include "pwd_grp_internal.c" 200#include "pwd_grp_internal.c"
229#endif
230 201
231#ifdef L_getgrnam_r 202#define GETXXKEY_R_FUNC getgrnam_R
232#define GETXXKEY_R_FUNC getgrnam_r
233#define GETXXKEY_R_PARSER __parsegrent 203#define GETXXKEY_R_PARSER __parsegrent
234#define GETXXKEY_R_ENTTYPE struct group 204#define GETXXKEY_R_ENTTYPE struct group
235#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key)) 205#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
236#define DO_GETXXKEY_R_KEYTYPE const char *__restrict 206#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
237#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP 207#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
238#include "pwd_grp_internal.c" 208#include "pwd_grp_internal.c"
239#endif
240 209
241#ifdef L_getspnam_r 210#define GETXXKEY_R_FUNC getspnam_R
242#define GETXXKEY_R_FUNC getspnam_r
243#define GETXXKEY_R_PARSER __parsespent 211#define GETXXKEY_R_PARSER __parsespent
244#define GETXXKEY_R_ENTTYPE struct spwd 212#define GETXXKEY_R_ENTTYPE struct spwd
245#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key)) 213#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
246#define DO_GETXXKEY_R_KEYTYPE const char *__restrict 214#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
247#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW 215#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
248#include "pwd_grp_internal.c" 216#include "pwd_grp_internal.c"
249#endif
250 217
251#ifdef L_getpwuid_r 218#define GETXXKEY_R_FUNC getpwuid_R
252#define GETXXKEY_R_FUNC getpwuid_r
253#define GETXXKEY_R_PARSER __parsepwent 219#define GETXXKEY_R_PARSER __parsepwent
254#define GETXXKEY_R_ENTTYPE struct passwd 220#define GETXXKEY_R_ENTTYPE struct passwd
255#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key) 221#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
256#define DO_GETXXKEY_R_KEYTYPE uid_t 222#define DO_GETXXKEY_R_KEYTYPE uid_t
257#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD 223#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
258#include "pwd_grp_internal.c" 224#include "pwd_grp_internal.c"
259#endif
260 225
261#ifdef L_getgrgid_r 226#define GETXXKEY_R_FUNC getgrgid_R
262#define GETXXKEY_R_FUNC getgrgid_r
263#define GETXXKEY_R_PARSER __parsegrent 227#define GETXXKEY_R_PARSER __parsegrent
264#define GETXXKEY_R_ENTTYPE struct group 228#define GETXXKEY_R_ENTTYPE struct group
265#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key) 229#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
266#define DO_GETXXKEY_R_KEYTYPE gid_t 230#define DO_GETXXKEY_R_KEYTYPE gid_t
267#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP 231#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
268#include "pwd_grp_internal.c" 232#include "pwd_grp_internal.c"
269#endif
270 233
271/**********************************************************************/ 234/**********************************************************************/
272#ifdef L_getpwuid
273 235
274struct passwd *getpwuid(uid_t uid) 236struct passwd *getpwuid(uid_t uid)
275{ 237{
@@ -281,10 +243,6 @@ struct passwd *getpwuid(uid_t uid)
281 return result; 243 return result;
282} 244}
283 245
284#endif
285/**********************************************************************/
286#ifdef L_getgrgid
287
288struct group *getgrgid(gid_t gid) 246struct group *getgrgid(gid_t gid)
289{ 247{
290 static char buffer[GRP_BUFFER_SIZE]; 248 static char buffer[GRP_BUFFER_SIZE];
@@ -295,10 +253,6 @@ struct group *getgrgid(gid_t gid)
295 return result; 253 return result;
296} 254}
297 255
298#endif
299/**********************************************************************/
300#ifdef L_getspuid_r
301
302/* This function is non-standard and is currently not built. It seems 256/* This function is non-standard and is currently not built. It seems
303 * to have been created as a reentrant version of the non-standard 257 * to have been created as a reentrant version of the non-standard
304 * functions getspuid. Why getspuid was added, I do not know. */ 258 * functions getspuid. Why getspuid was added, I do not know. */
@@ -320,10 +274,6 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
320 return rv; 274 return rv;
321} 275}
322 276
323#endif
324/**********************************************************************/
325#ifdef L_getspuid
326
327/* This function is non-standard and is currently not built. 277/* This function is non-standard and is currently not built.
328 * Why it was added, I do not know. */ 278 * Why it was added, I do not know. */
329 279
@@ -337,10 +287,6 @@ struct spwd *getspuid(uid_t uid)
337 return result; 287 return result;
338} 288}
339 289
340#endif
341/**********************************************************************/
342#ifdef L_getpwnam
343
344struct passwd *getpwnam(const char *name) 290struct passwd *getpwnam(const char *name)
345{ 291{
346 static char buffer[PWD_BUFFER_SIZE]; 292 static char buffer[PWD_BUFFER_SIZE];
@@ -351,10 +297,6 @@ struct passwd *getpwnam(const char *name)
351 return result; 297 return result;
352} 298}
353 299
354#endif
355/**********************************************************************/
356#ifdef L_getgrnam
357
358struct group *getgrnam(const char *name) 300struct group *getgrnam(const char *name)
359{ 301{
360 static char buffer[GRP_BUFFER_SIZE]; 302 static char buffer[GRP_BUFFER_SIZE];
@@ -365,10 +307,6 @@ struct group *getgrnam(const char *name)
365 return result; 307 return result;
366} 308}
367 309
368#endif
369/**********************************************************************/
370#ifdef L_getspnam
371
372struct spwd *getspnam(const char *name) 310struct spwd *getspnam(const char *name)
373{ 311{
374 static char buffer[PWD_BUFFER_SIZE]; 312 static char buffer[PWD_BUFFER_SIZE];
@@ -379,10 +317,6 @@ struct spwd *getspnam(const char *name)
379 return result; 317 return result;
380} 318}
381 319
382#endif
383/**********************************************************************/
384#ifdef L_getpw
385
386int getpw(uid_t uid, char *buf) 320int getpw(uid_t uid, char *buf)
387{ 321{
388 struct passwd resultbuf; 322 struct passwd resultbuf;
@@ -406,10 +340,8 @@ int getpw(uid_t uid, char *buf)
406 return -1; 340 return -1;
407} 341}
408 342
409#endif
410/**********************************************************************/ 343/**********************************************************************/
411 344
412#if defined(L_getpwent_r) || defined(L_getgrent_r) || defined(L_getspent_r)
413#if defined CONFIG_USE_BB_THREADSAFE_SHADOW && defined PTHREAD_MUTEX_INITIALIZER 345#if defined CONFIG_USE_BB_THREADSAFE_SHADOW && defined PTHREAD_MUTEX_INITIALIZER
414static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; 346static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
415# define LOCK pthread_mutex_lock(&mylock) 347# define LOCK pthread_mutex_lock(&mylock)
@@ -418,9 +350,7 @@ static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
418# define LOCK ((void) 0) 350# define LOCK ((void) 0)
419# define UNLOCK ((void) 0) 351# define UNLOCK ((void) 0)
420#endif 352#endif
421#endif
422 353
423#ifdef L_getpwent_r
424static FILE *pwf /*= NULL*/; 354static FILE *pwf /*= NULL*/;
425void setpwent(void) 355void setpwent(void)
426{ 356{
@@ -468,10 +398,6 @@ int getpwent_r(struct passwd *__restrict resultbuf,
468 return rv; 398 return rv;
469} 399}
470 400
471#endif
472/**********************************************************************/
473#ifdef L_getgrent_r
474
475static FILE *grf /*= NULL*/; 401static FILE *grf /*= NULL*/;
476void setgrent(void) 402void setgrent(void)
477{ 403{
@@ -518,10 +444,6 @@ int getgrent_r(struct group *__restrict resultbuf,
518 return rv; 444 return rv;
519} 445}
520 446
521#endif
522/**********************************************************************/
523#ifdef L_getspent_r
524
525static FILE *spf /*= NULL*/; 447static FILE *spf /*= NULL*/;
526void setspent(void) 448void setspent(void)
527{ 449{
@@ -567,10 +489,6 @@ int getspent_r(struct spwd *resultbuf, char *buffer,
567 return rv; 489 return rv;
568} 490}
569 491
570#endif
571/**********************************************************************/
572#ifdef L_getpwent
573
574struct passwd *getpwent(void) 492struct passwd *getpwent(void)
575{ 493{
576 static char line_buff[PWD_BUFFER_SIZE]; 494 static char line_buff[PWD_BUFFER_SIZE];
@@ -581,10 +499,6 @@ struct passwd *getpwent(void)
581 return result; 499 return result;
582} 500}
583 501
584#endif
585/**********************************************************************/
586#ifdef L_getgrent
587
588struct group *getgrent(void) 502struct group *getgrent(void)
589{ 503{
590 static char line_buff[GRP_BUFFER_SIZE]; 504 static char line_buff[GRP_BUFFER_SIZE];
@@ -595,10 +509,6 @@ struct group *getgrent(void)
595 return result; 509 return result;
596} 510}
597 511
598#endif
599/**********************************************************************/
600#ifdef L_getspent
601
602struct spwd *getspent(void) 512struct spwd *getspent(void)
603{ 513{
604 static char line_buff[PWD_BUFFER_SIZE]; 514 static char line_buff[PWD_BUFFER_SIZE];
@@ -609,10 +519,6 @@ struct spwd *getspent(void)
609 return result; 519 return result;
610} 520}
611 521
612#endif
613/**********************************************************************/
614#ifdef L_sgetspent
615
616struct spwd *sgetspent(const char *string) 522struct spwd *sgetspent(const char *string)
617{ 523{
618 static char line_buff[PWD_BUFFER_SIZE]; 524 static char line_buff[PWD_BUFFER_SIZE];
@@ -623,10 +529,6 @@ struct spwd *sgetspent(const char *string)
623 return result; 529 return result;
624} 530}
625 531
626#endif
627/**********************************************************************/
628#ifdef L_initgroups
629
630int initgroups(const char *user, gid_t gid) 532int initgroups(const char *user, gid_t gid)
631{ 533{
632 FILE *grfile; 534 FILE *grfile;
@@ -679,10 +581,6 @@ int initgroups(const char *user, gid_t gid)
679 return rv; 581 return rv;
680} 582}
681 583
682#endif
683/**********************************************************************/
684#ifdef L_putpwent
685
686int putpwent(const struct passwd *__restrict p, FILE *__restrict f) 584int putpwent(const struct passwd *__restrict p, FILE *__restrict f)
687{ 585{
688 int rv = -1; 586 int rv = -1;
@@ -704,10 +602,6 @@ int putpwent(const struct passwd *__restrict p, FILE *__restrict f)
704 return rv; 602 return rv;
705} 603}
706 604
707#endif
708/**********************************************************************/
709#ifdef L_putgrent
710
711int putgrent(const struct group *__restrict p, FILE *__restrict f) 605int putgrent(const struct group *__restrict p, FILE *__restrict f)
712{ 606{
713 static const char format[] = ",%s"; 607 static const char format[] = ",%s";
@@ -749,10 +643,6 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f)
749 return rv; 643 return rv;
750} 644}
751 645
752#endif
753/**********************************************************************/
754#ifdef L_putspent
755
756static const unsigned char _sp_off[] = { 646static const unsigned char _sp_off[] = {
757 offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */ 647 offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */
758 offsetof(struct spwd, sp_min), /* 3 - not a char ptr */ 648 offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
@@ -799,11 +689,9 @@ DO_UNLOCK:
799 return rv; 689 return rv;
800} 690}
801 691
802#endif
803/**********************************************************************/ 692/**********************************************************************/
804/* Internal uClibc functions. */ 693/* Internal uClibc functions. */
805/**********************************************************************/ 694/**********************************************************************/
806#ifdef L___parsepwent
807 695
808static const unsigned char pw_off[] = { 696static const unsigned char pw_off[] = {
809 offsetof(struct passwd, pw_name), /* 0 */ 697 offsetof(struct passwd, pw_name), /* 0 */
@@ -860,9 +748,7 @@ int __parsepwent(void *data, char *line)
860 return -1; 748 return -1;
861} 749}
862 750
863#endif
864/**********************************************************************/ 751/**********************************************************************/
865#ifdef L___parsegrent
866 752
867static const unsigned char gr_off[] = { 753static const unsigned char gr_off[] = {
868 offsetof(struct group, gr_name), /* 0 */ 754 offsetof(struct group, gr_name), /* 0 */
@@ -958,9 +844,7 @@ int __parsegrent(void *data, char *line)
958 return -1; 844 return -1;
959} 845}
960 846
961#endif
962/**********************************************************************/ 847/**********************************************************************/
963#ifdef L___parsespent
964 848
965static const unsigned char sp_off[] = { 849static const unsigned char sp_off[] = {
966 offsetof(struct spwd, sp_namp), /* 0 */ 850 offsetof(struct spwd, sp_namp), /* 0 */
@@ -1017,9 +901,7 @@ int __parsespent(void *data, char * line)
1017 return EINVAL; 901 return EINVAL;
1018} 902}
1019 903
1020#endif
1021/**********************************************************************/ 904/**********************************************************************/
1022#ifdef L___pgsreader
1023 905
1024/* Reads until if EOF, or until if finds a line which fits in the buffer 906/* Reads until if EOF, or until if finds a line which fits in the buffer
1025 * and for which the parser function succeeds. 907 * and for which the parser function succeeds.
@@ -1084,5 +966,4 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
1084 return rv; 966 return rv;
1085} 967}
1086 968
1087#endif
1088/**********************************************************************/ 969/**********************************************************************/
diff --git a/libpwdgrp/pwd_grp_internal.c b/libpwdgrp/pwd_grp_internal.c
index 39c11f677..866ed3699 100644
--- a/libpwdgrp/pwd_grp_internal.c
+++ b/libpwdgrp/pwd_grp_internal.c
@@ -18,96 +18,45 @@
18 * 18 *
19 */ 19 */
20 20
21#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>
28#include <assert.h>
29#include <ctype.h>
30
31#include "pwd_.h"
32#include "grp_.h"
33#include "shadow_.h"
34#include "libbb.h"
35
36#ifndef _PATH_SHADOW
37#define _PATH_SHADOW "/etc/shadow"
38#endif
39#ifndef _PATH_PASSWD
40#define _PATH_PASSWD "/etc/passwd"
41#endif
42#ifndef _PATH_GROUP
43#define _PATH_GROUP "/etc/group"
44#endif
45
46/**********************************************************************/
47/* Sizes for statically allocated buffers. */
48
49/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
50 * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
51#define PWD_BUFFER_SIZE 256
52#define GRP_BUFFER_SIZE 256
53
54/**********************************************************************/
55/* Prototypes for internal functions. */
56
57extern int __parsepwent(void *pw, char *line);
58extern int __parsegrent(void *gr, char *line);
59extern int __parsespent(void *sp, char *line);
60
61extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
62 char *__restrict line_buff, size_t buflen, FILE *f);
63
64
65#ifndef GETXXKEY_R_FUNC 21#ifndef GETXXKEY_R_FUNC
66#error GETXXKEY_R_FUNC is not defined! 22#error GETXXKEY_R_FUNC is not defined!
67#endif 23#endif
68/**********************************************************************/
69#ifdef GETXXKEY_R_FUNC
70 24
71int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key, 25int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
72 GETXXKEY_R_ENTTYPE *__restrict resultbuf, 26 GETXXKEY_R_ENTTYPE *__restrict resultbuf,
73 char *__restrict buffer, size_t buflen, 27 char *__restrict buffer, size_t buflen,
74 GETXXKEY_R_ENTTYPE **__restrict result) 28 GETXXKEY_R_ENTTYPE **__restrict result)
75{ 29{
76 FILE *stream; 30 FILE *stream;
77 int rv; 31 int rv;
78 32
79 *result = NULL; 33 *result = NULL;
80 34
81 if (!(stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"))) { 35 stream = fopen(DO_GETXXKEY_R_PATHNAME, "r");
82 rv = errno; 36 if (!stream)
83 } else { 37 return errno;
84 do { 38 while (1) {
85 if (!(rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf, 39 rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
86 buffer, buflen, stream)) 40 if (!rv) {
87 ) { 41 if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
88 if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */ 42 *result = resultbuf;
89 *result = resultbuf;
90 break;
91 }
92 } else {
93 if (rv == ENOENT) { /* end-of-file encountered. */
94 rv = 0;
95 }
96 break; 43 break;
97 } 44 }
98 } while (1); 45 } else {
99 fclose(stream); 46 if (rv == ENOENT) { /* end-of-file encountered. */
47 rv = 0;
48 }
49 break;
50 }
100 } 51 }
52 fclose(stream);
101 53
102 return rv; 54 return rv;
103} 55}
104 56
105#endif
106/**********************************************************************/
107#undef GETXXKEY_R_FUNC 57#undef GETXXKEY_R_FUNC
108#undef GETXXKEY_R_PARSER 58#undef GETXXKEY_R_PARSER
109#undef GETXXKEY_R_ENTTYPE 59#undef GETXXKEY_R_ENTTYPE
110#undef GETXXKEY_R_TEST 60#undef GETXXKEY_R_TEST
111#undef DO_GETXXKEY_R_KEYTYPE 61#undef DO_GETXXKEY_R_KEYTYPE
112#undef DO_GETXXKEY_R_PATHNAME 62#undef DO_GETXXKEY_R_PATHNAME
113