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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* nis/getspent.c -- "nis" backend for nsswitch "shadow" database
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <shadow.h>
#include <string.h>
#include "nis_common.h"
/*
* Most of the information in a struct spwd simply isn't available from the
* YP maps, we dummy out all the numeric fields and just get sp_namp and
* sp_pwdp (name and password) from the YP passwd map. Thus we don't
* use the str2ent() routine that's passed to us, but instead have our
* own dummy routine:
*
* 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. Let's not
* fight over crumbs.
*/
static int
nis_str2spent(instr, lenstr, ent, buffer, buflen)
const char *instr;
int lenstr;
void *ent; /* it is really (struct spwd *) */
char *buffer;
int buflen;
{
struct spwd *spwd = (struct spwd *)ent;
char *p, *q, *r;
/*
* We know that instr != 0 because we're in 'nis', not 'files'
*/
if ((p = memchr(instr, ':', lenstr)) == 0) {
return (NSS_STR_PARSE_PARSE);
}
if ((q = memchr(p + 1, ':', lenstr - (p + 1 - instr))) == 0) {
return (NSS_STR_PARSE_PARSE);
}
/* Don't bother checking the rest of the YP passwd entry... */
if (q + 1 - instr > buflen) {
return (NSS_STR_PARSE_ERANGE);
}
/*
* "name:password" is copied
*/
(void) memcpy(buffer, instr, q - instr);
if (spwd) {
buffer[p - instr] = '\0';
buffer[q - instr] = '\0';
spwd->sp_namp = buffer;
spwd->sp_pwdp = buffer + (p + 1 - instr);
spwd->sp_lstchg = -1;
spwd->sp_min = -1;
spwd->sp_max = -1;
spwd->sp_warn = -1;
spwd->sp_inact = -1;
spwd->sp_expire = -1;
spwd->sp_flag = 0;
} else {
/*
* NSS2: nscd is running. Return files format.
*
* name:password:::::::
*/
r = buffer + (q - instr);
*r = '\0';
if (strlcat(buffer, ":::::::", buflen) >= buflen)
return (NSS_STR_PARSE_ERANGE);
}
return (NSS_STR_PARSE_SUCCESS);
}
typedef int (*cstr2ent_t)(const char *, int, void *, char *, int);
static nss_status_t
getbyname(be, a)
nis_backend_ptr_t be;
void *a;
{
nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
cstr2ent_t save_c2e;
nss_status_t res;
struct spwd *spwd;
char *p;
save_c2e = argp->str2ent;
argp->str2ent = nis_str2spent;
res = _nss_nis_lookup(be, argp, 0, "passwd.byname", argp->key.name, 0);
spwd = (struct spwd *)argp->buf.result;
/*
* check for the C2 security flag "##" in the passwd field.
* If the first 2 chars in the passwd field is "##", get
* the user's passwd from passwd.adjunct.byname map.
* The lookup to this passwd.adjunct.byname map will only
* succeed if the caller's uid is 0 because only root user
* can use privilege port.
*/
if (res == NSS_SUCCESS) {
if (spwd) {
if ((spwd->sp_pwdp) && (*(spwd->sp_pwdp) == '#') &&
(*(spwd->sp_pwdp + 1) == '#')) {
/* get password from passwd.adjunct.byname */
res = _nss_nis_lookup_rsvdport(be, argp, 0,
"passwd.adjunct.byname",
argp->key.name, 0);
}
} else {
/*
* getent request from nscd
*/
if ((p = memchr(argp->buf.buffer, ':',
argp->buf.buflen)) == NULL)
return (NSS_STR_PARSE_PARSE);
if (strncmp(p + 1, "##", 2) == 0)
/* get password from passwd.adjunct.byname */
res = _nss_nis_lookup_rsvdport(be, argp, 0,
"passwd.adjunct.byname",
argp->key.name, 0);
if (res == NSS_SUCCESS) {
argp->returnval = argp->buf.buffer;
argp->returnlen = strlen(argp->buf.buffer);
}
}
}
argp->str2ent = save_c2e;
return (res);
}
#define NIS_SP_GETENT
#ifdef NIS_SP_GETENT
static nss_status_t
getent(be, a)
nis_backend_ptr_t be;
void *a;
{
nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
cstr2ent_t save_c2e;
nss_status_t res;
struct spwd *spwd;
char *p;
save_c2e = argp->str2ent;
argp->str2ent = nis_str2spent;
res = _nss_nis_getent_rigid(be, argp);
spwd = (struct spwd *)argp->buf.result;
/*
* check for the C2 security flag "##" in the passwd field.
* If the first 2 chars in the passwd field is "##", get
* the user's passwd from passwd.adjunct.byname map.
* The lookup to this passwd.adjunct.byname map will only
* succeed if the caller's uid is 0 because only root user
* can use privilege port.
*/
if (res == NSS_SUCCESS) {
if (spwd) {
if ((spwd->sp_pwdp) && (*(spwd->sp_pwdp) == '#') &&
(*(spwd->sp_pwdp + 1) == '#')) {
/* get password from passwd.adjunct.byname */
res = _nss_nis_lookup_rsvdport(be, argp, 0,
"passwd.adjunct.byname",
spwd->sp_namp, 0);
}
} else {
/*
* getent request from nscd
*/
if ((p = memchr(argp->buf.buffer, ':',
argp->buf.buflen)) == NULL)
return (NSS_STR_PARSE_PARSE);
if (strncmp(p + 1, "##", 2) == 0) {
/* need the name for the next search */
*p = '\0';
/* get password from passwd.adjunct.byname */
res = _nss_nis_lookup_rsvdport(be, argp, 0,
"passwd.adjunct.byname", p, 0);
}
if (res == NSS_SUCCESS) {
argp->returnval = argp->buf.buffer;
argp->returnlen = strlen(argp->buf.buffer);
}
}
}
argp->str2ent = save_c2e;
return (res);
}
#endif /* NIS_SP_GETENT */
static nis_backend_op_t shadow_ops[] = {
_nss_nis_destr,
_nss_nis_endent,
_nss_nis_setent,
#ifdef NIS_SP_GETENT
getent,
#else
0,
#endif /* NIS_SP_GETENT */
getbyname
};
/*ARGSUSED*/
nss_backend_t *
_nss_nis_shadow_constr(dummy1, dummy2, dummy3)
const char *dummy1, *dummy2, *dummy3;
{
return (_nss_nis_constr(shadow_ops,
sizeof (shadow_ops) / sizeof (shadow_ops[0]),
"passwd.byname"));
}
|