1 /* $NetBSD: pcnfsd_v2.c,v 1.9 2003/07/16 08:22:01 itojun Exp $ */
3 /* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_v2.c 1.2 91/12/18 13:26:13 SMI */
5 **=====================================================================
6 ** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
7 ** @(#)pcnfsd_v2.c 1.2 12/18/91
8 **=====================================================================
11 **=====================================================================
12 ** I N C L U D E F I L E S E C T I O N *
14 ** If your port requires different include files, add a suitable *
15 ** #define in the customization section, and make the inclusion or *
16 ** exclusion of the files conditional on this. *
17 **=====================================================================
21 #include <sys/ioctl.h>
34 #include <rpcsvc/ypclnt.h>
42 #include <sys/fcntl.h>
54 **=====================================================================
55 ** C O D E S E C T I O N *
56 **=====================================================================
60 static char no_comment
[] = "No comment";
61 static char not_supported
[] = "Not supported";
62 static char pcnfsd_version
[] = "@(#)pcnfsd_v2.c 1.2 - rpc.pcnfsd V2.0 (c) 1991 Sun Technology Enterprises, Inc.";
66 pcnfsd2_null_2_svc(arg
, req
)
71 return ((void *) &dummy
);
75 pcnfsd2_auth_2_svc(arg
, req
)
79 static v2_auth_results r
;
85 static u_int extra_gids
[EXTRAGIDLEN
];
86 static char home
[256];
93 r
.stat
= AUTH_RES_FAIL
; /* assume failure */
96 r
.cm
= &no_comment
[0];
98 r
.gids
.gids_val
= &extra_gids
[0];
101 r
.def_umask
= umask(0);
102 (void) umask(r
.def_umask
); /* or use 022 */
104 scramble(arg
->id
, uname
);
105 scramble(arg
->pw
, pw
);
108 if (check_cache(uname
, pw
, &r
.uid
, &r
.gid
)) {
109 r
.stat
= AUTH_RES_OK
;
114 (uname
, r
.gid
, &r
.gids
.gids_len
, extra_gids
);
116 yphome
= find_entry(uname
, "auto.home");
118 strlcpy(home
, yphome
, sizeof(home
));
120 cp
= strchr(home
, ':');
122 cp
= strchr(cp
, ':');
131 p
= get_password(uname
);
132 if (p
== (struct passwd
*) NULL
)
136 c2
= strlen(p
->pw_passwd
);
137 if ((c1
&& !c2
) || (c2
&& !c1
) ||
138 (strcmp(p
->pw_passwd
, crypt(pw
, p
->pw_passwd
)))) {
141 r
.stat
= AUTH_RES_OK
;
147 fillin_extra_groups(uname
, r
.gid
, &r
.gids
.gids_len
, extra_gids
);
150 yphome
= find_entry(uname
, "auto.home");
152 strlcpy(home
, yphome
, sizeof(home
));
154 cp
= strchr(home
, ':');
156 cp
= strchr(cp
, ':');
171 pcnfsd2_pr_init_2_svc(arg
, req
)
172 v2_pr_init_args
*arg
;
175 static v2_pr_init_results res
;
178 (pirstat
) pr_init(arg
->system
, arg
->pn
, &res
.dir
);
179 res
.cm
= &no_comment
[0];
185 v2_pr_start_results
*
186 pcnfsd2_pr_start_2_svc(arg
, req
)
187 v2_pr_start_args
*arg
;
190 static v2_pr_start_results res
;
193 (psrstat
) pr_start2(arg
->system
, arg
->pn
, arg
->user
,
194 arg
->file
, arg
->opts
, &res
.id
);
195 res
.cm
= &no_comment
[0];
201 pcnfsd2_pr_list_2_svc(arg
, req
)
205 static v2_pr_list_results res
;
207 if (printers
== NULL
)
208 (void) build_pr_list();
209 res
.cm
= &no_comment
[0];
210 res
.printers
= printers
;
215 v2_pr_queue_results
*
216 pcnfsd2_pr_queue_2_svc(arg
, req
)
217 v2_pr_queue_args
*arg
;
220 static v2_pr_queue_results res
;
222 res
.stat
= build_pr_queue(arg
->pn
, arg
->user
,
223 arg
->just_mine
, &res
.qlen
, &res
.qshown
);
224 res
.cm
= &no_comment
[0];
225 res
.just_yours
= arg
->just_mine
;
232 v2_pr_status_results
*
233 pcnfsd2_pr_status_2_svc(arg
, req
)
234 v2_pr_status_args
*arg
;
237 static v2_pr_status_results res
;
238 static char status
[128];
240 res
.stat
= get_pr_status(arg
->pn
, &res
.avail
, &res
.printing
,
241 &res
.qlen
, &res
.needs_operator
, &status
[0]);
242 res
.status
= &status
[0];
243 res
.cm
= &no_comment
[0];
248 v2_pr_cancel_results
*
249 pcnfsd2_pr_cancel_2_svc(arg
, req
)
250 v2_pr_cancel_args
*arg
;
253 static v2_pr_cancel_results res
;
255 res
.stat
= pr_cancel(arg
->pn
, arg
->user
, arg
->id
);
256 res
.cm
= &no_comment
[0];
261 v2_pr_requeue_results
*
262 pcnfsd2_pr_requeue_2_svc(arg
, req
)
263 v2_pr_requeue_args
*arg
;
266 static v2_pr_requeue_results res
;
267 res
.stat
= PC_RES_FAIL
;
268 res
.cm
= ¬_supported
[0];
274 pcnfsd2_pr_hold_2_svc(arg
, req
)
275 v2_pr_hold_args
*arg
;
278 static v2_pr_hold_results res
;
280 res
.stat
= PC_RES_FAIL
;
281 res
.cm
= ¬_supported
[0];
286 v2_pr_release_results
*
287 pcnfsd2_pr_release_2_svc(arg
, req
)
288 v2_pr_release_args
*arg
;
291 static v2_pr_release_results res
;
293 res
.stat
= PC_RES_FAIL
;
294 res
.cm
= ¬_supported
[0];
299 v2_pr_admin_results
*
300 pcnfsd2_pr_admin_2_svc(arg
, req
)
301 v2_pr_admin_args
*arg
;
304 static v2_pr_admin_results res
;
306 ** The default action for admin is to fail.
307 ** If someone wishes to implement an administration
308 ** mechanism, and isn't worried about the security
309 ** holes, go right ahead.
312 res
.cm
= ¬_supported
[0];
313 res
.stat
= PI_RES_FAIL
;
319 free_mapreq_results(p
)
323 free_mapreq_results(p
->mapreq_next
); /* recurse */
325 (void) free(p
->name
);
330 static char *my_strdup
__P((const char *));
337 r
= (char *) grab(strlen(s
) + 1);
338 strlcpy(r
, s
, strlen(s
) + 1);
343 pcnfsd2_mapid_2_svc(arg
, req
)
347 static v2_mapid_results res
;
348 struct passwd
*p_passwd
;
349 struct group
*p_group
;
353 mapreq_res last_r
= NULL
;
357 free_mapreq_results(res
.res_list
);
362 next_r
= (struct mapreq_res_item
*)
363 grab(sizeof(struct mapreq_res_item
));
364 next_r
->stat
= MAP_RES_UNKNOWN
;
365 next_r
->req
= a
->req
;
368 next_r
->mapreq_next
= NULL
;
371 res
.res_list
= next_r
;
373 last_r
->mapreq_next
= next_r
;
377 p_passwd
= getpwuid((uid_t
) a
->id
);
379 next_r
->name
= my_strdup(p_passwd
->pw_name
);
380 next_r
->stat
= MAP_RES_OK
;
384 p_group
= getgrgid((gid_t
) a
->id
);
386 next_r
->name
= my_strdup(p_group
->gr_name
);
387 next_r
->stat
= MAP_RES_OK
;
391 next_r
->name
= my_strdup(a
->name
);
392 p_passwd
= getpwnam(a
->name
);
394 next_r
->id
= p_passwd
->pw_uid
;
395 next_r
->stat
= MAP_RES_OK
;
399 next_r
->name
= my_strdup(a
->name
);
400 p_group
= getgrnam(a
->name
);
402 next_r
->id
= p_group
->gr_gid
;
403 next_r
->stat
= MAP_RES_OK
;
407 if (next_r
->name
== NULL
)
408 next_r
->name
= my_strdup("");
412 res
.cm
= &no_comment
[0];
420 pcnfsd2_alert_2_svc(arg
, req
)
424 static v2_alert_results res
;
426 res
.stat
= ALERT_RES_FAIL
;
427 res
.cm
= ¬_supported
[0];
433 pcnfsd2_info_2_svc(arg
, req
)
437 static v2_info_results res
;
438 static int facilities
[FACILITIESMAX
];
439 static int onetime
= 1;
441 #define UNSUPPORTED -1
447 facilities
[PCNFSD2_NULL
] = QUICK
;
448 facilities
[PCNFSD2_INFO
] = QUICK
;
449 facilities
[PCNFSD2_PR_INIT
] = QUICK
;
450 facilities
[PCNFSD2_PR_START
] = SLOW
;
451 facilities
[PCNFSD2_PR_LIST
] = QUICK
; /* except first time */
452 facilities
[PCNFSD2_PR_QUEUE
] = SLOW
;
453 facilities
[PCNFSD2_PR_STATUS
] = SLOW
;
454 facilities
[PCNFSD2_PR_CANCEL
] = SLOW
;
455 facilities
[PCNFSD2_PR_ADMIN
] = UNSUPPORTED
;
456 facilities
[PCNFSD2_PR_REQUEUE
] = UNSUPPORTED
;
457 facilities
[PCNFSD2_PR_HOLD
] = UNSUPPORTED
;
458 facilities
[PCNFSD2_PR_RELEASE
] = UNSUPPORTED
;
459 facilities
[PCNFSD2_MAPID
] = QUICK
;
460 facilities
[PCNFSD2_AUTH
] = QUICK
;
461 facilities
[PCNFSD2_ALERT
] = QUICK
;
463 res
.facilities
.facilities_len
= PCNFSD2_ALERT
+ 1;
464 res
.facilities
.facilities_val
= facilities
;
466 res
.vers
= &pcnfsd_version
[0];
467 res
.cm
= &no_comment
[0];
475 fillin_extra_groups(uname
, main_gid
, len
, extra_gids
)
479 gid_t extra_gids
[EXTRAGIDLEN
];
482 __aconst
char *__aconst
*members
;
487 while (n
< EXTRAGIDLEN
) {
491 if (grp
->gr_gid
== main_gid
)
493 for (members
= grp
->gr_mem
; members
&& *members
; members
++) {
494 if (!strcmp(*members
, uname
)) {
495 extra_gids
[n
++] = grp
->gr_gid
;
505 /* the following is from rpcsvc/yp_prot.h */
506 #define YPMAXDOMAIN 64
509 * find_entry returns NULL on any error (printing a message) and
510 * otherwise returns a pointer to the malloc'd result. The caller
511 * is responsible for free()ing the result string.
522 static char domain
[YPMAXDOMAIN
+ 1];
524 if (getdomainname(domain
, YPMAXDOMAIN
)) {
525 msg_out("rpc.pcnfsd: getdomainname failed");
528 if ((err
= yp_bind(domain
)) != 0) {
530 msg_out("rpc.pcnfsd: yp_bind failed");
534 err
= yp_match(domain
, map
, key
, strlen(key
), &val
, &len
);
537 msg_out("rpc.pcnfsd: yp_match failed");
542 if ((cp
= strchr(val
, '\n')) != NULL
)
543 *cp
= '\0'; /* in case we get an extra NL at the end */