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