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