diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-28 11:21:40 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-28 11:21:40 +0000 |
commit | 30c7de068b50de999b0b73a22e859dd2e9c23204 (patch) | |
tree | 1b77618915ceb3a318bb868addc1eb0e935cc758 /libpwdgrp/pwd_grp_internal.c | |
parent | 6973abcfa83a7fa51c963abc9040c8fc9a5af3a9 (diff) | |
download | busybox-w32-30c7de068b50de999b0b73a22e859dd2e9c23204.tar.gz busybox-w32-30c7de068b50de999b0b73a22e859dd2e9c23204.tar.bz2 busybox-w32-30c7de068b50de999b0b73a22e859dd2e9c23204.zip |
- move GETXXKEY_R_FUNC into an internal helper file to allow for compiling
with IMA.
Diffstat (limited to '')
-rw-r--r-- | libpwdgrp/pwd_grp_internal.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/libpwdgrp/pwd_grp_internal.c b/libpwdgrp/pwd_grp_internal.c new file mode 100644 index 000000000..d935b8622 --- /dev/null +++ b/libpwdgrp/pwd_grp_internal.c | |||
@@ -0,0 +1,111 @@ | |||
1 | /* Copyright (C) 2003 Manuel Novoa III | ||
2 | * | ||
3 | * Licensed under GPL v2, or later. See file LICENSE in this tarball. | ||
4 | */ | ||
5 | |||
6 | /* Nov 6, 2003 Initial version. | ||
7 | * | ||
8 | * NOTE: This implementation is quite strict about requiring all | ||
9 | * field seperators. It also does not allow leading whitespace | ||
10 | * except when processing the numeric fields. glibc is more | ||
11 | * lenient. See the various glibc difference comments below. | ||
12 | * | ||
13 | * TODO: | ||
14 | * Move to dynamic allocation of (currently staticly allocated) | ||
15 | * buffers; especially for the group-related functions since | ||
16 | * large group member lists will cause error returns. | ||
17 | * | ||
18 | */ | ||
19 | |||
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 | #include "busybox.h" | ||
30 | #include "pwd_.h" | ||
31 | #include "grp_.h" | ||
32 | #include "shadow_.h" | ||
33 | |||
34 | #ifndef _PATH_SHADOW | ||
35 | #define _PATH_SHADOW "/etc/shadow" | ||
36 | #endif | ||
37 | #ifndef _PATH_PASSWD | ||
38 | #define _PATH_PASSWD "/etc/passwd" | ||
39 | #endif | ||
40 | #ifndef _PATH_GROUP | ||
41 | #define _PATH_GROUP "/etc/group" | ||
42 | #endif | ||
43 | |||
44 | /**********************************************************************/ | ||
45 | /* Sizes for staticly allocated buffers. */ | ||
46 | |||
47 | /* If you change these values, also change _SC_GETPW_R_SIZE_MAX and | ||
48 | * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */ | ||
49 | #define PWD_BUFFER_SIZE 256 | ||
50 | #define GRP_BUFFER_SIZE 256 | ||
51 | |||
52 | /**********************************************************************/ | ||
53 | /* Prototypes for internal functions. */ | ||
54 | |||
55 | extern int __parsepwent(void *pw, char *line); | ||
56 | extern int __parsegrent(void *gr, char *line); | ||
57 | extern int __parsespent(void *sp, char *line); | ||
58 | |||
59 | extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, | ||
60 | char *__restrict line_buff, size_t buflen, FILE *f); | ||
61 | |||
62 | |||
63 | #ifndef GETXXKEY_R_FUNC | ||
64 | #error GETXXKEY_R_FUNC is not defined! | ||
65 | #endif | ||
66 | /**********************************************************************/ | ||
67 | #ifdef GETXXKEY_R_FUNC | ||
68 | |||
69 | int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key, | ||
70 | GETXXKEY_R_ENTTYPE *__restrict resultbuf, | ||
71 | char *__restrict buffer, size_t buflen, | ||
72 | GETXXKEY_R_ENTTYPE **__restrict result) | ||
73 | { | ||
74 | FILE *stream; | ||
75 | int rv; | ||
76 | |||
77 | *result = NULL; | ||
78 | |||
79 | if (!(stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"))) { | ||
80 | rv = errno; | ||
81 | } else { | ||
82 | do { | ||
83 | if (!(rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf, | ||
84 | buffer, buflen, stream)) | ||
85 | ) { | ||
86 | if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */ | ||
87 | *result = resultbuf; | ||
88 | break; | ||
89 | } | ||
90 | } else { | ||
91 | if (rv == ENOENT) { /* end-of-file encountered. */ | ||
92 | rv = 0; | ||
93 | } | ||
94 | break; | ||
95 | } | ||
96 | } while (1); | ||
97 | fclose(stream); | ||
98 | } | ||
99 | |||
100 | return rv; | ||
101 | } | ||
102 | |||
103 | #endif | ||
104 | /**********************************************************************/ | ||
105 | #undef GETXXKEY_R_FUNC | ||
106 | #undef GETXXKEY_R_PARSER | ||
107 | #undef GETXXKEY_R_ENTTYPE | ||
108 | #undef GETXXKEY_R_TEST | ||
109 | #undef DO_GETXXKEY_R_KEYTYPE | ||
110 | #undef DO_GETXXKEY_R_PATHNAME | ||
111 | |||