1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
Index: b/usr/src/cmd/getent/Makefile
===================================================================
--- a/usr/src/cmd/getent/Makefile
+++ b/usr/src/cmd/getent/Makefile
@@ -48,7 +48,7 @@ OBJECTS= \
SRCS= $(OBJECTS:.o=.c)
-LDLIBS += -lsocket -lnsl -lproject
+LDLIBS += -lsocket -lnsl
#
# for message catalog
Index: b/usr/src/cmd/getent/dogetproject.c
===================================================================
--- a/usr/src/cmd/getent/dogetproject.c
+++ b/usr/src/cmd/getent/dogetproject.c
@@ -29,9 +29,226 @@
#include <stdio.h>
#include <grp.h>
#include <stdlib.h>
-#include <project.h>
+#include <nss_dbdefs.h>
#include "getent.h"
+/* BEGIN: project.h */
+#define PROJF_PATH "/etc/project" /* pathname of the "project" file */
+#define PROJNAME_MAX 64 /* maximum project name size */
+#define PROJECT_BUFSZ 4096 /* default buffer size */
+
+struct project {
+ char *pj_name; /* name of the project */
+ projid_t pj_projid; /* numerical project id */
+ char *pj_comment; /* project description */
+ char **pj_users; /* vector of pointers to project user names */
+ char **pj_groups; /* vector of pointers to project group names */
+ char *pj_attr; /* project attributes string */
+};
+/* END: project.h */
+
+/* BEGIN: usr/src/lib/libproject/common/getprojent.c */
+static DEFINE_NSS_DB_ROOT(db_root);
+static DEFINE_NSS_GETENT(context);
+
+static void
+_nss_initf_project(nss_db_params_t *p)
+{
+ p->name = NSS_DBNAM_PROJECT;
+ p->default_config = NSS_DEFCONF_PROJECT;
+}
+
+static void
+setprojent(void)
+{
+ nss_setent(&db_root, _nss_initf_project, &context);
+}
+
+static void
+endprojent(void)
+{
+ nss_endent(&db_root, _nss_initf_project, &context);
+ nss_delete(&db_root);
+}
+
+static char *
+gettok(char **nextpp, char sep)
+{
+ char *p = *nextpp;
+ char *q = p;
+ char c;
+
+ if (p == NULL)
+ return (NULL);
+ while ((c = *q) != '\0' && c != sep)
+ q++;
+ if (c == '\0')
+ *nextpp = 0;
+ else {
+ *q++ = '\0';
+ *nextpp = q;
+ }
+ return (p);
+}
+
+/*
+ * Return values: 0 = success, 1 = parse error, 2 = erange ...
+ * The structure pointer passed in is a structure in the caller's space
+ * wherein the field pointers would be set to areas in the buffer if
+ * need be. instring and buffer should be separate areas.
+ */
+static int
+str2project(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
+{
+ struct project *project = ent;
+ char *p, *next;
+ char *users, *groups;
+ char **uglist;
+ char **limit;
+
+ if (lenstr + 1 > buflen)
+ return (NSS_STR_PARSE_ERANGE);
+ /*
+ * We copy the input string into the output buffer and
+ * operate on it in place.
+ */
+ (void) memcpy(buffer, instr, lenstr);
+ buffer[lenstr] = '\0';
+ next = buffer;
+
+ limit = (char **)ROUND_DOWN(buffer + buflen, sizeof (char *));
+
+ /*
+ * Parsers for passwd and group have always been pretty rigid;
+ * we wouldn't want to buck a Unix tradition
+ */
+ p = gettok(&next, ':');
+ if (p == NULL || *p == '\0' || strlen(p) > PROJNAME_MAX) {
+ /*
+ * empty or very long project names are not allowed
+ */
+ return (NSS_STR_PARSE_ERANGE);
+ }
+ project->pj_name = p;
+
+ p = gettok(&next, ':');
+ if (p == NULL || *p == '\0') {
+ /*
+ * projid field shouldn't be empty
+ */
+ return (NSS_STR_PARSE_PARSE);
+ }
+ project->pj_projid = (projid_t)strtol(p, NULL, 10);
+ if (project->pj_projid < 0) {
+ /*
+ * projids should be positive number
+ */
+ project->pj_projid = 0;
+ return (NSS_STR_PARSE_PARSE);
+ }
+
+ p = gettok(&next, ':');
+ if (p == NULL) {
+ /*
+ * comment field can be empty but should not be last field
+ */
+ return (NSS_STR_PARSE_PARSE);
+ }
+ project->pj_comment = p;
+
+ if ((users = gettok(&next, ':')) == NULL) {
+ /*
+ * users field should not be last field
+ */
+ return (NSS_STR_PARSE_PARSE);
+ }
+
+ if ((groups = gettok(&next, ':')) == NULL) {
+ /*
+ * groups field should not be last field
+ */
+ return (NSS_STR_PARSE_PARSE);
+ }
+
+ if (next == NULL) {
+ /*
+ * attributes field should be last
+ */
+ return (NSS_STR_PARSE_PARSE);
+ }
+
+ project->pj_attr = next;
+
+ uglist = (char **)ROUND_UP(buffer + lenstr + 1, sizeof (char *));
+ *uglist = NULL;
+ project->pj_users = uglist;
+ while (uglist < limit) {
+ p = gettok(&users, ',');
+ if (p == NULL || *p == '\0') {
+ *uglist = 0;
+ break;
+ }
+ *uglist++ = p;
+ }
+ if (uglist >= limit)
+ return (NSS_STR_PARSE_ERANGE);
+
+ uglist++;
+ *uglist = NULL;
+ project->pj_groups = uglist;
+ while (uglist < limit) {
+ p = gettok(&groups, ',');
+ if (p == NULL || *p == '\0') {
+ *uglist = 0;
+ break;
+ }
+ *uglist++ = p;
+ }
+ if (uglist >= limit)
+ return (NSS_STR_PARSE_ERANGE);
+
+ return (NSS_STR_PARSE_SUCCESS);
+}
+
+static struct project *
+getprojent(struct project *result, void *buffer, size_t buflen)
+{
+ nss_XbyY_args_t arg;
+
+ NSS_XbyY_INIT(&arg, result, buffer, buflen, str2project);
+ (void) nss_getent(&db_root, _nss_initf_project, &context, &arg);
+ return ((struct project *)NSS_XbyY_FINI(&arg));
+}
+
+struct project *
+getprojbyname(const char *name, struct project *result,
+ void *buffer, size_t buflen)
+{
+ nss_XbyY_args_t arg;
+ NSS_XbyY_INIT(&arg, result, buffer, buflen, str2project);
+ arg.key.name = name;
+ (void) nss_search(&db_root, _nss_initf_project,
+ NSS_DBOP_PROJECT_BYNAME, &arg);
+ return ((struct project *)NSS_XbyY_FINI(&arg));
+}
+
+struct project *
+getprojbyid(projid_t projid, struct project *result,
+ void *buffer, size_t buflen)
+{
+ nss_XbyY_args_t arg;
+
+ NSS_XbyY_INIT(&arg, result, buffer, buflen, str2project);
+ arg.key.projid = projid;
+ (void) nss_search(&db_root, _nss_initf_project,
+ NSS_DBOP_PROJECT_BYID, &arg);
+ return ((struct project *)NSS_XbyY_FINI(&arg));
+}
+
+
+
+/* END: usr/src/lib/libproject/common/getprojent.c */
+
static int
putprojent(const struct project *proj, FILE *fp)
{
|