pcnfsd_v2.c revision 1.2 1 1.2 gwr /* $NetBSD: pcnfsd_v2.c,v 1.2 1995/07/25 22:21:33 gwr Exp $ */
2 1.2 gwr
3 1.1 jtc /* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_v2.c 1.2 91/12/18 13:26:13 SMI */
4 1.1 jtc /*
5 1.1 jtc **=====================================================================
6 1.1 jtc ** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
7 1.1 jtc ** @(#)pcnfsd_v2.c 1.2 12/18/91
8 1.1 jtc **=====================================================================
9 1.1 jtc */
10 1.1 jtc #include "common.h"
11 1.1 jtc /*
12 1.1 jtc **=====================================================================
13 1.1 jtc ** I N C L U D E F I L E S E C T I O N *
14 1.1 jtc ** *
15 1.1 jtc ** If your port requires different include files, add a suitable *
16 1.1 jtc ** #define in the customization section, and make the inclusion or *
17 1.1 jtc ** exclusion of the files conditional on this. *
18 1.1 jtc **=====================================================================
19 1.1 jtc */
20 1.1 jtc #include "pcnfsd.h"
21 1.1 jtc
22 1.1 jtc #include <stdio.h>
23 1.1 jtc #include <pwd.h>
24 1.1 jtc #include <grp.h>
25 1.1 jtc #include <sys/file.h>
26 1.1 jtc #include <signal.h>
27 1.1 jtc #include <sys/stat.h>
28 1.1 jtc #include <sys/ioctl.h>
29 1.1 jtc #include <netdb.h>
30 1.1 jtc #include <string.h>
31 1.1 jtc
32 1.1 jtc #ifdef USE_YP
33 1.1 jtc #include <rpcsvc/ypclnt.h>
34 1.1 jtc #endif
35 1.1 jtc
36 1.1 jtc #ifndef SYSV
37 1.1 jtc #include <sys/wait.h>
38 1.1 jtc #endif
39 1.1 jtc
40 1.1 jtc #ifdef ISC_2_0
41 1.1 jtc #include <sys/fcntl.h>
42 1.1 jtc #endif
43 1.1 jtc
44 1.1 jtc #ifdef SHADOW_SUPPORT
45 1.1 jtc #include <shadow.h>
46 1.1 jtc #endif
47 1.1 jtc
48 1.1 jtc /*
49 1.1 jtc **---------------------------------------------------------------------
50 1.1 jtc ** Other #define's
51 1.1 jtc **---------------------------------------------------------------------
52 1.1 jtc */
53 1.1 jtc
54 1.1 jtc void fillin_extra_groups();
55 1.1 jtc extern void scramble();
56 1.1 jtc extern void *grab();
57 1.1 jtc extern char *crypt();
58 1.1 jtc extern int build_pr_list();
59 1.1 jtc extern pirstat build_pr_queue();
60 1.1 jtc extern psrstat pr_start();
61 1.1 jtc extern psrstat pr_start2();
62 1.1 jtc extern pcrstat pr_cancel();
63 1.1 jtc extern pirstat get_pr_status();
64 1.1 jtc
65 1.1 jtc extern struct passwd *get_password();
66 1.1 jtc
67 1.1 jtc #ifdef WTMP
68 1.1 jtc extern void wlogin();
69 1.1 jtc #endif
70 1.1 jtc
71 1.1 jtc #ifdef USE_YP
72 1.1 jtc char *find_entry();
73 1.1 jtc #endif
74 1.1 jtc
75 1.1 jtc /*
76 1.1 jtc **---------------------------------------------------------------------
77 1.1 jtc ** Misc. variable definitions
78 1.1 jtc **---------------------------------------------------------------------
79 1.1 jtc */
80 1.1 jtc
81 1.1 jtc extern pr_list printers;
82 1.1 jtc extern pr_queue queue;
83 1.1 jtc
84 1.1 jtc /*
85 1.1 jtc **=====================================================================
86 1.1 jtc ** C O D E S E C T I O N * **=====================================================================
87 1.1 jtc */
88 1.1 jtc
89 1.1 jtc
90 1.1 jtc static char no_comment[] = "No comment";
91 1.1 jtc static char not_supported[] = "Not supported";
92 1.1 jtc static char pcnfsd_version[] = "@(#)pcnfsd_v2.c 1.2 - rpc.pcnfsd V2.0 (c) 1991 Sun Technology Enterprises, Inc.";
93 1.1 jtc
94 1.1 jtc /*ARGSUSED*/
95 1.1 jtc void *pcnfsd2_null_2_svc(arg, req)
96 1.1 jtc void*arg;
97 1.1 jtc struct svc_req *req;
98 1.1 jtc {
99 1.1 jtc static char dummy;
100 1.1 jtc return((void *)&dummy);
101 1.1 jtc }
102 1.1 jtc
103 1.1 jtc v2_auth_results *pcnfsd2_auth_2_svc(arg, req)
104 1.1 jtc v2_auth_args *arg;
105 1.1 jtc struct svc_req *req;
106 1.1 jtc {
107 1.1 jtc static v2_auth_results r;
108 1.1 jtc
109 1.1 jtc char uname[32];
110 1.1 jtc char pw[64];
111 1.1 jtc int c1, c2;
112 1.1 jtc struct passwd *p;
113 1.1 jtc static u_int extra_gids[EXTRAGIDLEN];
114 1.1 jtc static char home[256];
115 1.1 jtc #ifdef USE_YP
116 1.1 jtc char *yphome;
117 1.1 jtc char *cp;
118 1.1 jtc #endif /*USE_YP*/
119 1.1 jtc
120 1.1 jtc
121 1.1 jtc r.stat = AUTH_RES_FAIL; /* assume failure */
122 1.1 jtc r.uid = (int)-2;
123 1.1 jtc r.gid = (int)-2;
124 1.1 jtc r.cm = &no_comment[0];
125 1.1 jtc r.gids.gids_len = 0;
126 1.1 jtc r.gids.gids_val = &extra_gids[0];
127 1.1 jtc home[0] = '\0';
128 1.1 jtc r.home = &home[0];
129 1.1 jtc r.def_umask = umask(0);
130 1.1 jtc (void)umask(r.def_umask); /* or use 022 */
131 1.1 jtc
132 1.1 jtc scramble(arg->id, uname);
133 1.1 jtc scramble(arg->pw, pw);
134 1.1 jtc
135 1.1 jtc #ifdef USER_CACHE
136 1.1 jtc if(check_cache(uname, pw, &r.uid, &r.gid)) {
137 1.1 jtc r.stat = AUTH_RES_OK;
138 1.1 jtc #ifdef WTMP
139 1.1 jtc wlogin(uname, req);
140 1.1 jtc #endif
141 1.1 jtc fillin_extra_groups
142 1.1 jtc (uname, r.gid, &r.gids.gids_len, extra_gids);
143 1.1 jtc #ifdef USE_YP
144 1.1 jtc yphome = find_entry(uname, "auto.home");
145 1.1 jtc if(yphome) {
146 1.1 jtc strcpy(home, yphome);
147 1.1 jtc free(yphome);
148 1.1 jtc cp = strchr(home, ':');
149 1.1 jtc cp++;
150 1.1 jtc cp = strchr(cp, ':');
151 1.1 jtc if(cp)
152 1.1 jtc *cp = '/';
153 1.1 jtc }
154 1.1 jtc #endif
155 1.1 jtc return (&r);
156 1.1 jtc }
157 1.1 jtc #endif
158 1.1 jtc
159 1.1 jtc p = get_password(uname);
160 1.1 jtc if (p == (struct passwd *)NULL)
161 1.1 jtc return (&r);
162 1.1 jtc
163 1.1 jtc c1 = strlen(pw);
164 1.1 jtc c2 = strlen(p->pw_passwd);
165 1.1 jtc if ((c1 && !c2) || (c2 && !c1) ||
166 1.1 jtc (strcmp(p->pw_passwd, crypt(pw, p->pw_passwd))))
167 1.1 jtc {
168 1.1 jtc return (&r);
169 1.1 jtc }
170 1.1 jtc r.stat = AUTH_RES_OK;
171 1.1 jtc r.uid = p->pw_uid;
172 1.1 jtc r.gid = p->pw_gid;
173 1.1 jtc #ifdef WTMP
174 1.1 jtc wlogin(uname, req);
175 1.1 jtc #endif
176 1.1 jtc fillin_extra_groups(uname, r.gid, &r.gids.gids_len, extra_gids);
177 1.1 jtc
178 1.1 jtc #ifdef USE_YP
179 1.1 jtc yphome = find_entry(uname, "auto.home");
180 1.1 jtc if(yphome) {
181 1.1 jtc strcpy(home, yphome);
182 1.1 jtc free(yphome);
183 1.1 jtc cp = strchr(home, ':');
184 1.1 jtc cp++;
185 1.1 jtc cp = strchr(cp, ':');
186 1.1 jtc if(cp)
187 1.1 jtc *cp = '/';
188 1.1 jtc }
189 1.1 jtc #endif
190 1.1 jtc
191 1.1 jtc #ifdef USER_CACHE
192 1.1 jtc add_cache_entry(p);
193 1.1 jtc #endif
194 1.1 jtc
195 1.1 jtc return(&r);
196 1.1 jtc
197 1.1 jtc }
198 1.1 jtc
199 1.1 jtc v2_pr_init_results *pcnfsd2_pr_init_2_svc(arg, req)
200 1.1 jtc v2_pr_init_args *arg;
201 1.1 jtc struct svc_req *req;
202 1.1 jtc {
203 1.1 jtc static v2_pr_init_results res;
204 1.1 jtc
205 1.1 jtc res.stat =
206 1.1 jtc (pirstat) pr_init(arg->system, arg->pn, &res.dir);
207 1.1 jtc res.cm = &no_comment[0];
208 1.1 jtc
209 1.1 jtc
210 1.1 jtc return(&res);
211 1.1 jtc }
212 1.1 jtc
213 1.1 jtc v2_pr_start_results *pcnfsd2_pr_start_2_svc(arg, req)
214 1.1 jtc v2_pr_start_args *arg;
215 1.1 jtc struct svc_req *req;
216 1.1 jtc {
217 1.1 jtc static v2_pr_start_results res;
218 1.1 jtc
219 1.1 jtc res.stat =
220 1.1 jtc (psrstat) pr_start2(arg->system, arg->pn, arg->user,
221 1.1 jtc arg ->file, arg->opts, &res.id);
222 1.1 jtc res.cm = &no_comment[0];
223 1.1 jtc
224 1.1 jtc return(&res);
225 1.1 jtc }
226 1.1 jtc
227 1.1 jtc /*ARGSUSED*/
228 1.1 jtc v2_pr_list_results *pcnfsd2_pr_list_2_svc(arg, req)
229 1.1 jtc void *arg;
230 1.1 jtc struct svc_req *req;
231 1.1 jtc {
232 1.1 jtc static v2_pr_list_results res;
233 1.1 jtc
234 1.1 jtc if(printers == NULL)
235 1.1 jtc (void)build_pr_list();
236 1.1 jtc res.cm = &no_comment[0];
237 1.1 jtc res.printers = printers;
238 1.1 jtc
239 1.1 jtc return(&res);
240 1.1 jtc }
241 1.1 jtc
242 1.1 jtc v2_pr_queue_results *pcnfsd2_pr_queue_2_svc(arg, req)
243 1.1 jtc v2_pr_queue_args *arg;
244 1.1 jtc struct svc_req *req;
245 1.1 jtc {
246 1.1 jtc static v2_pr_queue_results res;
247 1.1 jtc
248 1.1 jtc res.stat = build_pr_queue(arg->pn, arg->user,
249 1.1 jtc arg->just_mine, &res.qlen, &res.qshown);
250 1.1 jtc res.cm = &no_comment[0];
251 1.1 jtc res.just_yours = arg->just_mine;
252 1.1 jtc res.jobs = queue;
253 1.1 jtc
254 1.1 jtc
255 1.1 jtc return(&res);
256 1.1 jtc }
257 1.1 jtc
258 1.1 jtc v2_pr_status_results *pcnfsd2_pr_status_2_svc(arg, req)
259 1.1 jtc v2_pr_status_args *arg;
260 1.1 jtc struct svc_req *req;
261 1.1 jtc {
262 1.1 jtc static v2_pr_status_results res;
263 1.1 jtc static char status[128];
264 1.1 jtc
265 1.1 jtc res.stat = get_pr_status(arg->pn, &res.avail, &res.printing,
266 1.1 jtc &res.qlen, &res.needs_operator, &status[0]);
267 1.1 jtc res.status = &status[0];
268 1.1 jtc res.cm = &no_comment[0];
269 1.1 jtc
270 1.1 jtc return(&res);
271 1.1 jtc }
272 1.1 jtc
273 1.1 jtc v2_pr_cancel_results *pcnfsd2_pr_cancel_2_svc(arg, req)
274 1.1 jtc v2_pr_cancel_args *arg;
275 1.1 jtc struct svc_req *req;
276 1.1 jtc {
277 1.1 jtc static v2_pr_cancel_results res;
278 1.1 jtc
279 1.1 jtc res.stat = pr_cancel(arg->pn, arg->user, arg->id);
280 1.1 jtc res.cm = &no_comment[0];
281 1.1 jtc
282 1.1 jtc return(&res);
283 1.1 jtc }
284 1.1 jtc
285 1.1 jtc /*ARGSUSED*/
286 1.1 jtc v2_pr_requeue_results *pcnfsd2_pr_requeue_2_svc(arg, req)
287 1.1 jtc v2_pr_requeue_args *arg;
288 1.1 jtc struct svc_req *req;
289 1.1 jtc {
290 1.1 jtc static v2_pr_requeue_results res;
291 1.1 jtc res.stat = PC_RES_FAIL;
292 1.1 jtc res.cm = ¬_supported[0];
293 1.1 jtc
294 1.1 jtc return(&res);
295 1.1 jtc }
296 1.1 jtc
297 1.1 jtc /*ARGSUSED*/
298 1.1 jtc v2_pr_hold_results *pcnfsd2_pr_hold_2_svc(arg, req)
299 1.1 jtc v2_pr_hold_args *arg;
300 1.1 jtc struct svc_req *req;
301 1.1 jtc {
302 1.1 jtc static v2_pr_hold_results res;
303 1.1 jtc
304 1.1 jtc res.stat = PC_RES_FAIL;
305 1.1 jtc res.cm = ¬_supported[0];
306 1.1 jtc
307 1.1 jtc return(&res);
308 1.1 jtc }
309 1.1 jtc
310 1.1 jtc /*ARGSUSED*/
311 1.1 jtc v2_pr_release_results *pcnfsd2_pr_release_2_svc(arg, req)
312 1.1 jtc v2_pr_release_args *arg;
313 1.1 jtc struct svc_req *req;
314 1.1 jtc {
315 1.1 jtc static v2_pr_release_results res;
316 1.1 jtc
317 1.1 jtc res.stat = PC_RES_FAIL;
318 1.1 jtc res.cm = ¬_supported[0];
319 1.1 jtc
320 1.1 jtc return(&res);
321 1.1 jtc }
322 1.1 jtc
323 1.1 jtc /*ARGSUSED*/
324 1.1 jtc v2_pr_admin_results *pcnfsd2_pr_admin_2_svc(arg, req)
325 1.1 jtc v2_pr_admin_args *arg;
326 1.1 jtc struct svc_req *req;
327 1.1 jtc {
328 1.1 jtc static v2_pr_admin_results res;
329 1.1 jtc /*
330 1.1 jtc ** The default action for admin is to fail.
331 1.1 jtc ** If someone wishes to implement an administration
332 1.1 jtc ** mechanism, and isn't worried about the security
333 1.1 jtc ** holes, go right ahead.
334 1.1 jtc */
335 1.1 jtc
336 1.1 jtc res.cm = ¬_supported[0];
337 1.1 jtc res.stat = PI_RES_FAIL;
338 1.1 jtc
339 1.1 jtc return(&res);
340 1.1 jtc }
341 1.1 jtc
342 1.1 jtc void
343 1.1 jtc free_mapreq_results(p)
344 1.1 jtc mapreq_res p;
345 1.1 jtc {
346 1.1 jtc if(p->mapreq_next)
347 1.1 jtc free_mapreq_results(p->mapreq_next); /* recurse */
348 1.1 jtc if(p->name)
349 1.1 jtc (void)free(p->name);
350 1.1 jtc (void)free(p);
351 1.1 jtc return;
352 1.1 jtc }
353 1.1 jtc
354 1.1 jtc static char *
355 1.1 jtc my_strdup(s)
356 1.1 jtc char *s;
357 1.1 jtc {
358 1.1 jtc char *r;
359 1.1 jtc r = (char *)grab(strlen(s)+1);
360 1.1 jtc strcpy(r, s);
361 1.1 jtc return(r);
362 1.1 jtc }
363 1.1 jtc
364 1.1 jtc v2_mapid_results *pcnfsd2_mapid_2_svc(arg, req)
365 1.1 jtc v2_mapid_args *arg;
366 1.1 jtc struct svc_req *req;
367 1.1 jtc {
368 1.1 jtc static v2_mapid_results res;
369 1.1 jtc struct passwd *p_passwd;
370 1.1 jtc struct group *p_group;
371 1.1 jtc
372 1.1 jtc mapreq_arg a;
373 1.1 jtc mapreq_res next_r;
374 1.1 jtc mapreq_res last_r = NULL;
375 1.1 jtc
376 1.1 jtc
377 1.1 jtc if(res.res_list) {
378 1.1 jtc free_mapreq_results(res.res_list);
379 1.1 jtc res.res_list = NULL;
380 1.1 jtc }
381 1.1 jtc
382 1.1 jtc a = arg->req_list;
383 1.1 jtc while(a) {
384 1.1 jtc next_r = (struct mapreq_res_item *)
385 1.1 jtc grab(sizeof(struct mapreq_res_item));
386 1.1 jtc next_r->stat = MAP_RES_UNKNOWN;
387 1.1 jtc next_r->req = a->req;
388 1.1 jtc next_r->id = a->id;
389 1.1 jtc next_r->name = NULL;
390 1.1 jtc next_r->mapreq_next = NULL;
391 1.1 jtc
392 1.1 jtc if(last_r == NULL)
393 1.1 jtc res.res_list = next_r;
394 1.1 jtc else
395 1.1 jtc last_r->mapreq_next = next_r;
396 1.1 jtc last_r = next_r;
397 1.1 jtc switch(a->req) {
398 1.1 jtc case MAP_REQ_UID:
399 1.1 jtc p_passwd = getpwuid((uid_t)a->id);
400 1.1 jtc if(p_passwd) {
401 1.1 jtc next_r->name = my_strdup(p_passwd->pw_name);
402 1.1 jtc next_r->stat = MAP_RES_OK;
403 1.1 jtc }
404 1.1 jtc break;
405 1.1 jtc case MAP_REQ_GID:
406 1.1 jtc p_group = getgrgid((gid_t)a->id);
407 1.1 jtc if(p_group) {
408 1.1 jtc next_r->name = my_strdup(p_group->gr_name);
409 1.1 jtc next_r->stat = MAP_RES_OK;
410 1.1 jtc }
411 1.1 jtc break;
412 1.1 jtc case MAP_REQ_UNAME:
413 1.1 jtc next_r->name = my_strdup(a->name);
414 1.1 jtc p_passwd = getpwnam(a->name);
415 1.1 jtc if(p_passwd) {
416 1.1 jtc next_r->id = p_passwd->pw_uid;
417 1.1 jtc next_r->stat = MAP_RES_OK;
418 1.1 jtc }
419 1.1 jtc break;
420 1.1 jtc case MAP_REQ_GNAME:
421 1.1 jtc next_r->name = my_strdup(a->name);
422 1.1 jtc p_group = getgrnam(a->name);
423 1.1 jtc if(p_group) {
424 1.1 jtc next_r->id = p_group->gr_gid;
425 1.1 jtc next_r->stat = MAP_RES_OK;
426 1.1 jtc }
427 1.1 jtc break;
428 1.1 jtc }
429 1.1 jtc if(next_r->name == NULL)
430 1.1 jtc next_r->name = my_strdup("");
431 1.1 jtc a = a->mapreq_next;
432 1.1 jtc }
433 1.1 jtc
434 1.1 jtc res.cm = &no_comment[0];
435 1.1 jtc
436 1.1 jtc return(&res);
437 1.1 jtc }
438 1.1 jtc
439 1.1 jtc
440 1.1 jtc /*ARGSUSED*/
441 1.1 jtc v2_alert_results *pcnfsd2_alert_2_svc(arg, req)
442 1.1 jtc v2_alert_args *arg;
443 1.1 jtc struct svc_req *req;
444 1.1 jtc {
445 1.1 jtc static v2_alert_results res;
446 1.1 jtc
447 1.1 jtc res.stat = ALERT_RES_FAIL;
448 1.1 jtc res.cm = ¬_supported[0];
449 1.1 jtc
450 1.1 jtc return(&res);
451 1.1 jtc }
452 1.1 jtc
453 1.1 jtc /*ARGSUSED*/
454 1.1 jtc v2_info_results *pcnfsd2_info_2_svc(arg, req)
455 1.1 jtc v2_info_args *arg;
456 1.1 jtc struct svc_req *req;
457 1.1 jtc {
458 1.1 jtc static v2_info_results res;
459 1.1 jtc static int facilities[FACILITIESMAX];
460 1.1 jtc static int onetime = 1;
461 1.1 jtc
462 1.1 jtc #define UNSUPPORTED -1
463 1.1 jtc #define QUICK 100
464 1.1 jtc #define SLOW 2000
465 1.1 jtc
466 1.1 jtc if(onetime) {
467 1.1 jtc onetime = 0;
468 1.1 jtc facilities[PCNFSD2_NULL] = QUICK;
469 1.1 jtc facilities[PCNFSD2_INFO] = QUICK;
470 1.1 jtc facilities[PCNFSD2_PR_INIT] = QUICK;
471 1.1 jtc facilities[PCNFSD2_PR_START] = SLOW;
472 1.1 jtc facilities[PCNFSD2_PR_LIST] = QUICK; /* except first time */
473 1.1 jtc facilities[PCNFSD2_PR_QUEUE] = SLOW;
474 1.1 jtc facilities[PCNFSD2_PR_STATUS] = SLOW;
475 1.1 jtc facilities[PCNFSD2_PR_CANCEL] = SLOW;
476 1.1 jtc facilities[PCNFSD2_PR_ADMIN] = UNSUPPORTED;
477 1.1 jtc facilities[PCNFSD2_PR_REQUEUE] = UNSUPPORTED;
478 1.1 jtc facilities[PCNFSD2_PR_HOLD] = UNSUPPORTED;
479 1.1 jtc facilities[PCNFSD2_PR_RELEASE] = UNSUPPORTED;
480 1.1 jtc facilities[PCNFSD2_MAPID] = QUICK;
481 1.1 jtc facilities[PCNFSD2_AUTH] = QUICK;
482 1.1 jtc facilities[PCNFSD2_ALERT] = QUICK;
483 1.1 jtc }
484 1.1 jtc res.facilities.facilities_len = PCNFSD2_ALERT+1;
485 1.1 jtc res.facilities.facilities_val = facilities;
486 1.1 jtc
487 1.1 jtc res.vers = &pcnfsd_version[0];
488 1.1 jtc res.cm = &no_comment[0];
489 1.1 jtc
490 1.1 jtc return(&res);
491 1.1 jtc }
492 1.1 jtc
493 1.1 jtc
494 1.1 jtc
495 1.1 jtc void
496 1.1 jtc fillin_extra_groups(uname, main_gid, len, extra_gids)
497 1.1 jtc char *uname;
498 1.1 jtc u_int main_gid;
499 1.1 jtc int *len;
500 1.1 jtc u_int extra_gids[EXTRAGIDLEN];
501 1.1 jtc {
502 1.1 jtc struct group *grp;
503 1.1 jtc char **members;
504 1.1 jtc int n = 0;
505 1.1 jtc
506 1.1 jtc setgrent();
507 1.1 jtc
508 1.1 jtc while(n < EXTRAGIDLEN) {
509 1.1 jtc grp = getgrent();
510 1.1 jtc if(grp == NULL)
511 1.1 jtc break;
512 1.1 jtc if(grp->gr_gid == main_gid)
513 1.1 jtc continue;
514 1.1 jtc for(members = grp->gr_mem; members && *members; members++) {
515 1.1 jtc if(!strcmp(*members, uname)) {
516 1.1 jtc extra_gids[n++] = grp->gr_gid;
517 1.1 jtc break;
518 1.1 jtc }
519 1.1 jtc }
520 1.1 jtc }
521 1.1 jtc endgrent();
522 1.1 jtc *len = n;
523 1.1 jtc }
524 1.1 jtc
525 1.1 jtc #ifdef USE_YP
526 1.1 jtc /* the following is from rpcsvc/yp_prot.h */
527 1.1 jtc #define YPMAXDOMAIN 64
528 1.1 jtc /*
529 1.1 jtc * find_entry returns NULL on any error (printing a message) and
530 1.1 jtc * otherwise returns a pointer to the malloc'd result. The caller
531 1.1 jtc * is responsible for free()ing the result string.
532 1.1 jtc */
533 1.1 jtc char *
534 1.1 jtc find_entry(key, map)
535 1.1 jtc char *key;
536 1.1 jtc char *map;
537 1.1 jtc {
538 1.1 jtc int err;
539 1.1 jtc char *val = NULL;
540 1.1 jtc char *cp;
541 1.1 jtc int len = 0;
542 1.1 jtc static char domain[YPMAXDOMAIN+1];
543 1.1 jtc
544 1.1 jtc if(getdomainname(domain, YPMAXDOMAIN) ) {
545 1.1 jtc msg_out("rpc.pcnfsd: getdomainname failed");
546 1.1 jtc return(NULL);
547 1.1 jtc }
548 1.1 jtc
549 1.1 jtc if (err = yp_bind(domain)) {
550 1.1 jtc msg_out("rpc.pcnfsd: yp_bind failed");
551 1.1 jtc return(NULL);
552 1.1 jtc }
553 1.1 jtc
554 1.1 jtc err = yp_match(domain, map, key, strlen(key), &val, &len);
555 1.1 jtc
556 1.1 jtc if (err) {
557 1.1 jtc msg_out("rpc.pcnfsd: yp_match failed");
558 1.1 jtc return(NULL);
559 1.1 jtc }
560 1.1 jtc
561 1.1 jtc if(cp = strchr(val, '\n'))
562 1.1 jtc *cp = '\0'; /* in case we get an extra NL at the end */
563 1.1 jtc return(val);
564 1.1 jtc }
565 1.1 jtc
566 1.1 jtc #endif
567