NetBSD/usr.sbin/rpc.pcnfsd/pcnfsd_v2.c

547 lines
11 KiB
C
Raw Normal View History

1997-10-25 17:45:55 +04:00
/* $NetBSD: pcnfsd_v2.c,v 1.6 1997/10/25 13:46:00 lukem Exp $ */
1995-07-26 02:20:13 +04:00
1995-07-24 08:02:44 +04:00
/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_v2.c 1.2 91/12/18 13:26:13 SMI */
/*
**=====================================================================
** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
** @(#)pcnfsd_v2.c 1.2 12/18/91
**=====================================================================
*/
/*
**=====================================================================
** I N C L U D E F I L E S E C T I O N *
** *
** If your port requires different include files, add a suitable *
** #define in the customization section, and make the inclusion or *
** exclusion of the files conditional on this. *
**=====================================================================
*/
#include <sys/file.h>
#include <sys/ioctl.h>
1997-10-25 17:45:55 +04:00
#include <sys/stat.h>
#include <grp.h>
1995-07-24 08:02:44 +04:00
#include <netdb.h>
1997-10-25 17:45:55 +04:00
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
1995-07-24 08:02:44 +04:00
#include <string.h>
1997-10-25 17:45:55 +04:00
#include <unistd.h>
1995-07-24 08:02:44 +04:00
#ifdef USE_YP
#include <rpcsvc/ypclnt.h>
#endif
#ifndef SYSV
#include <sys/wait.h>
#endif
#ifdef ISC_2_0
#include <sys/fcntl.h>
#endif
#ifdef SHADOW_SUPPORT
#include <shadow.h>
#endif
1997-10-25 17:45:55 +04:00
#include "common.h"
#include "pcnfsd.h"
#include "extern.h"
1995-07-24 08:02:44 +04:00
/*
**=====================================================================
1995-08-14 23:50:09 +04:00
** C O D E S E C T I O N *
**=====================================================================
1995-07-24 08:02:44 +04:00
*/
static char no_comment[] = "No comment";
static char not_supported[] = "Not supported";
static char pcnfsd_version[] = "@(#)pcnfsd_v2.c 1.2 - rpc.pcnfsd V2.0 (c) 1991 Sun Technology Enterprises, Inc.";
/*ARGSUSED*/
1997-10-25 17:45:55 +04:00
void *
pcnfsd2_null_2_svc(arg, req)
void *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static char dummy;
return ((void *) &dummy);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
v2_auth_results *
pcnfsd2_auth_2_svc(arg, req)
v2_auth_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_auth_results r;
char uname[32];
char pw[64];
int c1, c2;
struct passwd *p;
static u_int extra_gids[EXTRAGIDLEN];
static char home[256];
1995-07-24 08:02:44 +04:00
#ifdef USE_YP
1997-10-25 17:45:55 +04:00
char *yphome;
char *cp;
#endif /* USE_YP */
1995-07-24 08:02:44 +04:00
r.stat = AUTH_RES_FAIL; /* assume failure */
1997-10-25 17:45:55 +04:00
r.uid = (int) -2;
r.gid = (int) -2;
1995-07-24 08:02:44 +04:00
r.cm = &no_comment[0];
r.gids.gids_len = 0;
r.gids.gids_val = &extra_gids[0];
home[0] = '\0';
r.home = &home[0];
r.def_umask = umask(0);
1997-10-25 17:45:55 +04:00
(void) umask(r.def_umask); /* or use 022 */
1995-07-24 08:02:44 +04:00
scramble(arg->id, uname);
scramble(arg->pw, pw);
#ifdef USER_CACHE
1997-10-25 17:45:55 +04:00
if (check_cache(uname, pw, &r.uid, &r.gid)) {
r.stat = AUTH_RES_OK;
1995-07-24 08:02:44 +04:00
#ifdef WTMP
wlogin(uname, req);
#endif
1997-10-25 17:45:55 +04:00
fillin_extra_groups
(uname, r.gid, &r.gids.gids_len, extra_gids);
1995-07-24 08:02:44 +04:00
#ifdef USE_YP
yphome = find_entry(uname, "auto.home");
1997-10-25 17:45:55 +04:00
if (yphome) {
1995-07-24 08:02:44 +04:00
strcpy(home, yphome);
free(yphome);
cp = strchr(home, ':');
cp++;
cp = strchr(cp, ':');
1997-10-25 17:45:55 +04:00
if (cp)
1995-07-24 08:02:44 +04:00
*cp = '/';
}
#endif
1997-10-25 17:45:55 +04:00
return (&r);
}
1995-07-24 08:02:44 +04:00
#endif
p = get_password(uname);
1997-10-25 17:45:55 +04:00
if (p == (struct passwd *) NULL)
return (&r);
1995-07-24 08:02:44 +04:00
c1 = strlen(pw);
c2 = strlen(p->pw_passwd);
if ((c1 && !c2) || (c2 && !c1) ||
1997-10-25 17:45:55 +04:00
(strcmp(p->pw_passwd, crypt(pw, p->pw_passwd)))) {
return (&r);
}
1995-07-24 08:02:44 +04:00
r.stat = AUTH_RES_OK;
r.uid = p->pw_uid;
r.gid = p->pw_gid;
#ifdef WTMP
wlogin(uname, req);
#endif
1997-10-25 17:45:55 +04:00
fillin_extra_groups(uname, r.gid, &r.gids.gids_len, extra_gids);
1995-07-24 08:02:44 +04:00
#ifdef USE_YP
yphome = find_entry(uname, "auto.home");
1997-10-25 17:45:55 +04:00
if (yphome) {
1995-07-24 08:02:44 +04:00
strcpy(home, yphome);
free(yphome);
cp = strchr(home, ':');
cp++;
cp = strchr(cp, ':');
1997-10-25 17:45:55 +04:00
if (cp)
1995-07-24 08:02:44 +04:00
*cp = '/';
}
#endif
#ifdef USER_CACHE
add_cache_entry(p);
#endif
1997-10-25 17:45:55 +04:00
return (&r);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
v2_pr_init_results *
pcnfsd2_pr_init_2_svc(arg, req)
v2_pr_init_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_init_results res;
1995-07-24 08:02:44 +04:00
1997-10-25 17:45:55 +04:00
res.stat =
(pirstat) pr_init(arg->system, arg->pn, &res.dir);
1995-07-24 08:02:44 +04:00
res.cm = &no_comment[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
v2_pr_start_results *
pcnfsd2_pr_start_2_svc(arg, req)
v2_pr_start_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_start_results res;
1995-07-24 08:02:44 +04:00
res.stat =
1997-10-25 17:45:55 +04:00
(psrstat) pr_start2(arg->system, arg->pn, arg->user,
arg->file, arg->opts, &res.id);
1995-07-24 08:02:44 +04:00
res.cm = &no_comment[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
/*ARGSUSED*/
1997-10-25 17:45:55 +04:00
v2_pr_list_results *
pcnfsd2_pr_list_2_svc(arg, req)
void *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_list_results res;
1995-07-24 08:02:44 +04:00
1997-10-25 17:45:55 +04:00
if (printers == NULL)
(void) build_pr_list();
1995-07-24 08:02:44 +04:00
res.cm = &no_comment[0];
res.printers = printers;
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
v2_pr_queue_results *
pcnfsd2_pr_queue_2_svc(arg, req)
v2_pr_queue_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_queue_results res;
1995-07-24 08:02:44 +04:00
res.stat = build_pr_queue(arg->pn, arg->user,
1997-10-25 17:45:55 +04:00
arg->just_mine, &res.qlen, &res.qshown);
1995-07-24 08:02:44 +04:00
res.cm = &no_comment[0];
res.just_yours = arg->just_mine;
res.jobs = queue;
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
v2_pr_status_results *
pcnfsd2_pr_status_2_svc(arg, req)
v2_pr_status_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_status_results res;
static char status[128];
1995-07-24 08:02:44 +04:00
res.stat = get_pr_status(arg->pn, &res.avail, &res.printing,
1997-10-25 17:45:55 +04:00
&res.qlen, &res.needs_operator, &status[0]);
res.status = &status[0];
1995-07-24 08:02:44 +04:00
res.cm = &no_comment[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
v2_pr_cancel_results *
pcnfsd2_pr_cancel_2_svc(arg, req)
v2_pr_cancel_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_cancel_results res;
1995-07-24 08:02:44 +04:00
res.stat = pr_cancel(arg->pn, arg->user, arg->id);
res.cm = &no_comment[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
/*ARGSUSED*/
1997-10-25 17:45:55 +04:00
v2_pr_requeue_results *
pcnfsd2_pr_requeue_2_svc(arg, req)
v2_pr_requeue_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_requeue_results res;
1995-07-24 08:02:44 +04:00
res.stat = PC_RES_FAIL;
res.cm = &not_supported[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
/*ARGSUSED*/
1997-10-25 17:45:55 +04:00
v2_pr_hold_results *
pcnfsd2_pr_hold_2_svc(arg, req)
v2_pr_hold_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_hold_results res;
1995-07-24 08:02:44 +04:00
res.stat = PC_RES_FAIL;
res.cm = &not_supported[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
/*ARGSUSED*/
1997-10-25 17:45:55 +04:00
v2_pr_release_results *
pcnfsd2_pr_release_2_svc(arg, req)
v2_pr_release_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_release_results res;
1995-07-24 08:02:44 +04:00
res.stat = PC_RES_FAIL;
res.cm = &not_supported[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
/*ARGSUSED*/
1997-10-25 17:45:55 +04:00
v2_pr_admin_results *
pcnfsd2_pr_admin_2_svc(arg, req)
v2_pr_admin_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_pr_admin_results res;
1995-07-24 08:02:44 +04:00
/*
** The default action for admin is to fail.
** If someone wishes to implement an administration
** mechanism, and isn't worried about the security
** holes, go right ahead.
*/
res.cm = &not_supported[0];
res.stat = PI_RES_FAIL;
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
void
free_mapreq_results(p)
1997-10-25 17:45:55 +04:00
mapreq_res p;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
if (p->mapreq_next)
free_mapreq_results(p->mapreq_next); /* recurse */
if (p->name)
(void) free(p->name);
(void) free(p);
1995-07-24 08:02:44 +04:00
return;
}
1997-10-25 17:45:55 +04:00
static char *my_strdup __P((char *));
1995-07-24 08:02:44 +04:00
static char *
my_strdup(s)
1997-10-25 17:45:55 +04:00
char *s;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
char *r;
r = (char *) grab(strlen(s) + 1);
1995-07-24 08:02:44 +04:00
strcpy(r, s);
1997-10-25 17:45:55 +04:00
return (r);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
v2_mapid_results *
pcnfsd2_mapid_2_svc(arg, req)
v2_mapid_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_mapid_results res;
struct passwd *p_passwd;
struct group *p_group;
1995-07-24 08:02:44 +04:00
1997-10-25 17:45:55 +04:00
mapreq_arg a;
mapreq_res next_r;
mapreq_res last_r = NULL;
1995-07-24 08:02:44 +04:00
1997-10-25 17:45:55 +04:00
if (res.res_list) {
1995-07-24 08:02:44 +04:00
free_mapreq_results(res.res_list);
res.res_list = NULL;
}
a = arg->req_list;
1997-10-25 17:45:55 +04:00
while (a) {
1995-07-24 08:02:44 +04:00
next_r = (struct mapreq_res_item *)
1997-10-25 17:45:55 +04:00
grab(sizeof(struct mapreq_res_item));
1995-07-24 08:02:44 +04:00
next_r->stat = MAP_RES_UNKNOWN;
next_r->req = a->req;
next_r->id = a->id;
next_r->name = NULL;
next_r->mapreq_next = NULL;
1997-10-25 17:45:55 +04:00
if (last_r == NULL)
1995-07-24 08:02:44 +04:00
res.res_list = next_r;
else
last_r->mapreq_next = next_r;
last_r = next_r;
1997-10-25 17:45:55 +04:00
switch (a->req) {
1995-07-24 08:02:44 +04:00
case MAP_REQ_UID:
1997-10-25 17:45:55 +04:00
p_passwd = getpwuid((uid_t) a->id);
if (p_passwd) {
1995-07-24 08:02:44 +04:00
next_r->name = my_strdup(p_passwd->pw_name);
next_r->stat = MAP_RES_OK;
}
break;
case MAP_REQ_GID:
1997-10-25 17:45:55 +04:00
p_group = getgrgid((gid_t) a->id);
if (p_group) {
1995-07-24 08:02:44 +04:00
next_r->name = my_strdup(p_group->gr_name);
next_r->stat = MAP_RES_OK;
}
break;
case MAP_REQ_UNAME:
next_r->name = my_strdup(a->name);
p_passwd = getpwnam(a->name);
1997-10-25 17:45:55 +04:00
if (p_passwd) {
1995-07-24 08:02:44 +04:00
next_r->id = p_passwd->pw_uid;
next_r->stat = MAP_RES_OK;
}
break;
case MAP_REQ_GNAME:
next_r->name = my_strdup(a->name);
p_group = getgrnam(a->name);
1997-10-25 17:45:55 +04:00
if (p_group) {
1995-07-24 08:02:44 +04:00
next_r->id = p_group->gr_gid;
next_r->stat = MAP_RES_OK;
}
break;
}
1997-10-25 17:45:55 +04:00
if (next_r->name == NULL)
1995-07-24 08:02:44 +04:00
next_r->name = my_strdup("");
a = a->mapreq_next;
}
res.cm = &no_comment[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
1995-07-24 08:02:44 +04:00
/*ARGSUSED*/
1997-10-25 17:45:55 +04:00
v2_alert_results *
pcnfsd2_alert_2_svc(arg, req)
v2_alert_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_alert_results res;
1995-07-24 08:02:44 +04:00
res.stat = ALERT_RES_FAIL;
res.cm = &not_supported[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
/*ARGSUSED*/
1997-10-25 17:45:55 +04:00
v2_info_results *
pcnfsd2_info_2_svc(arg, req)
v2_info_args *arg;
struct svc_req *req;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
static v2_info_results res;
static int facilities[FACILITIESMAX];
static int onetime = 1;
1995-07-24 08:02:44 +04:00
#define UNSUPPORTED -1
#define QUICK 100
#define SLOW 2000
1997-10-25 17:45:55 +04:00
if (onetime) {
1995-07-24 08:02:44 +04:00
onetime = 0;
facilities[PCNFSD2_NULL] = QUICK;
facilities[PCNFSD2_INFO] = QUICK;
facilities[PCNFSD2_PR_INIT] = QUICK;
facilities[PCNFSD2_PR_START] = SLOW;
1997-10-25 17:45:55 +04:00
facilities[PCNFSD2_PR_LIST] = QUICK; /* except first time */
1995-07-24 08:02:44 +04:00
facilities[PCNFSD2_PR_QUEUE] = SLOW;
facilities[PCNFSD2_PR_STATUS] = SLOW;
facilities[PCNFSD2_PR_CANCEL] = SLOW;
facilities[PCNFSD2_PR_ADMIN] = UNSUPPORTED;
facilities[PCNFSD2_PR_REQUEUE] = UNSUPPORTED;
facilities[PCNFSD2_PR_HOLD] = UNSUPPORTED;
facilities[PCNFSD2_PR_RELEASE] = UNSUPPORTED;
facilities[PCNFSD2_MAPID] = QUICK;
facilities[PCNFSD2_AUTH] = QUICK;
facilities[PCNFSD2_ALERT] = QUICK;
}
1997-10-25 17:45:55 +04:00
res.facilities.facilities_len = PCNFSD2_ALERT + 1;
1995-07-24 08:02:44 +04:00
res.facilities.facilities_val = facilities;
1997-10-25 17:45:55 +04:00
1995-07-24 08:02:44 +04:00
res.vers = &pcnfsd_version[0];
res.cm = &no_comment[0];
1997-10-25 17:45:55 +04:00
return (&res);
1995-07-24 08:02:44 +04:00
}
void
fillin_extra_groups(uname, main_gid, len, extra_gids)
1997-10-25 17:45:55 +04:00
char *uname;
gid_t main_gid;
int *len;
gid_t extra_gids[EXTRAGIDLEN];
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
struct group *grp;
char **members;
int n = 0;
1995-07-24 08:02:44 +04:00
setgrent();
1997-10-25 17:45:55 +04:00
while (n < EXTRAGIDLEN) {
1995-07-24 08:02:44 +04:00
grp = getgrent();
1997-10-25 17:45:55 +04:00
if (grp == NULL)
1995-07-24 08:02:44 +04:00
break;
1997-10-25 17:45:55 +04:00
if (grp->gr_gid == main_gid)
1995-07-24 08:02:44 +04:00
continue;
1997-10-25 17:45:55 +04:00
for (members = grp->gr_mem; members && *members; members++) {
if (!strcmp(*members, uname)) {
1995-07-24 08:02:44 +04:00
extra_gids[n++] = grp->gr_gid;
break;
}
}
}
endgrent();
*len = n;
}
#ifdef USE_YP
/* the following is from rpcsvc/yp_prot.h */
#define YPMAXDOMAIN 64
1997-10-25 17:45:55 +04:00
1995-07-24 08:02:44 +04:00
/*
* find_entry returns NULL on any error (printing a message) and
* otherwise returns a pointer to the malloc'd result. The caller
* is responsible for free()ing the result string.
*/
1997-10-25 17:45:55 +04:00
char *
1995-07-24 08:02:44 +04:00
find_entry(key, map)
1997-10-25 17:45:55 +04:00
char *key;
char *map;
1995-07-24 08:02:44 +04:00
{
1997-10-25 17:45:55 +04:00
int err;
char *val = NULL;
char *cp;
int len = 0;
static char domain[YPMAXDOMAIN + 1];
1995-07-24 08:02:44 +04:00
1997-10-25 17:45:55 +04:00
if (getdomainname(domain, YPMAXDOMAIN)) {
1995-07-24 08:02:44 +04:00
msg_out("rpc.pcnfsd: getdomainname failed");
1997-10-25 17:45:55 +04:00
return (NULL);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
if ((err = yp_bind(domain)) != 0) {
#ifdef DEBUG
1995-07-24 08:02:44 +04:00
msg_out("rpc.pcnfsd: yp_bind failed");
#endif
1997-10-25 17:45:55 +04:00
return (NULL);
1995-07-24 08:02:44 +04:00
}
err = yp_match(domain, map, key, strlen(key), &val, &len);
if (err) {
msg_out("rpc.pcnfsd: yp_match failed");
if (val)
free(val);
1997-10-25 17:45:55 +04:00
return (NULL);
1995-07-24 08:02:44 +04:00
}
1997-10-25 17:45:55 +04:00
if ((cp = strchr(val, '\n')) != NULL)
*cp = '\0'; /* in case we get an extra NL at the end */
return (val);
1995-07-24 08:02:44 +04:00
}
#endif