[7892] in Athena Bugs

home help back first fref pref prev next nref lref last post

nfsc

daemon@ATHENA.MIT.EDU (John Carr)
Fri Aug 9 10:19:33 1991

To: bugs@ATHENA.MIT.EDU
Date: Fri, 09 Aug 91 10:19:42 EDT
From: John Carr <jfc@ATHENA.MIT.EDU>


Included are changes to nfsc to edit the credentials database.  There are
also unrelated changes to support AIX and get the mapctl structure
definition from a header file.  This change requires that dbmcred.h (found
in the rpc.mountd source) be in the include path.

One use for this feature would be to allow instant updates of NFS group
lists and addition of new users to the credentials file.  It should also be
useful for private workstation maintainers.

Example of use of new features:

	nfsc adduser systest 13891 101 13891
	nfsc deluser systest

It is possible for mountd to get confused by changes, but that should happen
only if nfsc loses the CPU between the writes to the .dir and .pag file and
rpc.mountd accesses the record being modified before nfsc finishes the
update.  I think this is very unlikely.


*** ref/machdep.h	Tue Jan  8 11:21:44 1991
--- machdep.h	Sun Jul 28 18:47:33 1991
***************
*** 16,22 ****
   * have to do it ourselves
   */
  
! #if defined(ultrix) && !defined(ULTRIX_40)
  typedef int  rpc_uid_t;
  typedef int  rpc_gid_t;
  #endif
--- 16,22 ----
   * have to do it ourselves
   */
  
! #if (defined(ultrix) && !defined(ULTRIX_40)) || defined(_AIX)
  typedef int  rpc_uid_t;
  typedef int  rpc_gid_t;
  #endif
*** ref/nfsc_kludge.c	Sun Aug  9 12:49:15 1987
--- nfsc_kludge.c	Sun Jul 28 19:47:09 1991
***************
*** 28,37 ****
--- 28,51 ----
  extern long lseek();
  
  static struct nlist nl[] = {
+ #ifdef _AIX
  #define NFS_USEMAP 0
+ 	{ "nfs_usemap" },
+ #else
+ #define NFS_USEMAP 0
  	{ "_nfs_usemap" },
+ #endif
  	{ NULL },
  };
+ 
+ int nlist_done;
+ 
+ #ifdef _AIX
+ #define	KERNEL "/unix"
+ #else
+ #define	KERNEL "/vmunix"
+ #endif
+ 
  static int on = 1;
  static int off = 0;
  
***************
*** 43,52 ****
  	int fd;
  	int nfsmap_on;
  	
! 	if (nlist("/vmunix", nl) != 0) {
! 		printf("nlist failure: are you on an NFS mapping server?\n");
  		return(1);
  	}
  	nfsmap_on = nl[NFS_USEMAP].n_value;
  
  	if ((fd = open("/dev/kmem", O_WRONLY, 0)) < 0) {
--- 57,67 ----
  	int fd;
  	int nfsmap_on;
  
! 	if (!nlist_done && nlist(KERNEL, nl) != 0) {
! 		fputs("nlist failure: are you on an NFS mapping server?\n",stderr);
  		return(1);
  	}
+ 	nlist_done = 1;
  	nfsmap_on = nl[NFS_USEMAP].n_value;
  
  	if ((fd = open("/dev/kmem", O_WRONLY, 0)) < 0) {
*** ref/mapctl.c	Thu Nov  8 15:48:11 1990
--- mapctl.c	Sun Jul 28 20:06:39 1991
***************
*** 11,13 ****
--- 11,23 ----
  	RET
  .end nfsmapctl
  #endif
+ #ifdef i386
+ #ifndef SYS_nfsmapctl
+ #define SYS_nfsmapctl 64
+ #endif
+ #include <sys.s>
+ 	.globl	nfsmapctl
+ nfsmapctl:
+ 	SCALL0 SYS_nfsmapctl
+ 	ret
+ #endif
*** ref/Imakefile	Mon Jul 22 14:09:48 1991
--- Imakefile	Sun Jul 28 20:07:22 1991
***************
*** 14,23 ****
  #ifdef ultrix
  MACHOBJ=mapctl.o
  #endif
  
  LIBS= -lss -lcom_err
  
! #if !defined(vax) && !defined(ibm032) && !defined(ultrix)
  all install::
  	@echo \`nfsc\' is not available on this platform
  
--- 14,28 ----
  #ifdef ultrix
  MACHOBJ=mapctl.o
  #endif
+ #ifdef _AIX
+ CFLAGS=$(CDEBUG) -I$(ATHINCDIR) $(DEFINES)
+ MACHOBJ=mapctl.o
+ LDDEFS=-T0x400000
+ #endif
  
  LIBS= -lss -lcom_err
  
! #if !defined(vax) && !defined(ibm032) && !defined(ultrix) && AIXV!=12
  all install::
  	@echo \`nfsc\' is not available on this platform
  
***************
*** 34,42 ****
--- 39,54 ----
  	@echo "Building mapctl.o..."
  	as mapctl.c -o mapctl.o
  #else
+ #ifdef i386
  mapctl.o: mapctl.c
  	@echo "Building mapctl.o..."
+ 	$(CC) $(CFLAGS) -E -c mapctl.c | as
+ 	mv a.out mapctl.o
+ #else
+ mapctl.o: mapctl.c
+ 	@echo "Building mapctl.o..."
  	$(CC) $(CFLAGS) -E -c mapctl.c | as -o mapctl.o
+ #endif
  #endif
  
  #endif /* build nfsc */
*** ref/nfsc_show.c	Thu Nov  8 15:37:00 1990
--- nfsc_show.c	Sun Jul 28 20:16:44 1991
***************
*** 25,31 ****
   */
  
  #ifndef lint
! static char *rcsid_nfsc_show_c = "$Header: /afs/rel-eng.athena.mit.edu/project/release/current/source/bsd-4.3/common/usr.etc/nfsc/RCS/nfsc_show.c,v 1.5 90/11/08 15:36:53 probe Exp $";
  #endif lint
  
  #include <stdio.h>
--- 25,31 ----
   */
  
  #ifndef lint
! static char *rcsid_nfsc_show_c = "$Header: nfsc_show.c 1.5 90/11/08 15:36:53 probe Exp $";
  #endif lint
  
  #include <stdio.h>
***************
*** 35,67 ****
  #include <nlist.h>
  #include <netdb.h>
  #include "machdep.h"
  
  extern char *malloc();
  extern void perror();
  extern long lseek();
  
- /*
-  * It should get this out of a header file..
-  */
- 
- struct nfsmap_ent {
- 	struct nfsmap_ent *e_next;
- 	struct nfsmap_ent *e_prev;
- 	int e_uid;
- 	struct sockaddr e_sock;
- 	int e_len;
- 	struct authunix_parms *e_credp;
- 	u_short e_rfcnt;
- };
- 
  struct nfsmap_ent *nfsmap_htable[256];
! static struct nlist nl[] = { { "_nfsmap_htable" },
  #define	NFSMAP_HTABLE	0
  		      { "_nfs_usemap" },
  #define NFSMAP_ON	1
  		      { "" },
  		       };
  
  int fd;
  int nfsmap_on;
  caddr_t get_offset();
--- 35,69 ----
  #include <nlist.h>
  #include <netdb.h>
  #include "machdep.h"
+ #include <nfs/nfs_mapctl.h>
  
  extern char *malloc();
  extern void perror();
  extern long lseek();
  
  struct nfsmap_ent *nfsmap_htable[256];
! static struct nlist nl[] = {
! #ifdef _AIX
!   { "nfsmap_htable" },
! #else
!   { "_nfsmap_htable" },
! #endif
  #define	NFSMAP_HTABLE	0
+ #ifdef _AIX
+   { "nfs_usemap" },
+ #else
    { "_nfs_usemap" },
+ #endif
  #define NFSMAP_ON	1
    { "" },
  };
  
+ #ifdef _AIX
+ #define	KERNEL "/unix"
+ #else
+ #define	KERNEL "/vmunix"
+ #endif
+ 
  int fd;
  int nfsmap_on;
  caddr_t get_offset();
***************
*** 75,86 ****
  	register int i;
  	register struct nfsmap_ent *ent;
  	u_int mapoff;
! 	if (nlist("/vmunix", nl) != 0) {
  		printf ("nlist failure: are you on an NFS mapping server?\n");
  		return (1);
  	}
  	nfsmap_on = nl[NFSMAP_ON].n_value;
  	mapoff = nl[NFSMAP_HTABLE].n_value;
  	if ((fd = open ("/dev/kmem", 0, 0)) < 0) {
  		perror("cannot open /dev/kmem");
  		return (1);
--- 77,93 ----
  	register int i;
  	register struct nfsmap_ent *ent;
  	u_int mapoff;
! 	if (nlist(KERNEL, nl) != 0) {
  		printf ("nlist failure: are you on an NFS mapping server?\n");
  		return (1);
  	}
  	nfsmap_on = nl[NFSMAP_ON].n_value;
  	mapoff = nl[NFSMAP_HTABLE].n_value;
+ 	if (mapoff == 0) {
+ 		printf ("nlist failure: are you on an NFS mapping server?\n");
+ 		return (1);
+ 	}
+ 
  	if ((fd = open ("/dev/kmem", 0, 0)) < 0) {
  		perror("cannot open /dev/kmem");
  		return (1);
***************
*** 89,98 ****
  	lseek (fd, nfsmap_on, L_SET);
  	read (fd, &nfsmap_on, sizeof (int));
  	printf ("NFS Mapping is %s\n", nfsmap_on ? "on" : "off");
! #endif notdef
  	lseek (fd, (long)mapoff, L_SET);
! 	if (read (fd, (char *)nfsmap_htable, 256 * sizeof (caddr_t))
! 	    < 0) {
  		perror("kernel read error");
  		close(fd);
  		return (1);
--- 96,104 ----
  	lseek (fd, nfsmap_on, L_SET);
  	read (fd, &nfsmap_on, sizeof (int));
  	printf ("NFS Mapping is %s\n", nfsmap_on ? "on" : "off");
! #endif
  	lseek (fd, (long)mapoff, L_SET);
! 	if (read (fd, (char *)nfsmap_htable, 256 * sizeof (caddr_t)) < 0) {
  		perror("kernel read error");
  		close(fd);
  		return (1);
*** ref/getgrps.c	Tue Jan  8 11:21:14 1991
--- getgrps.c	Sun Jul 28 20:25:54 1991
***************
*** 34,40 ****
--- 34,44 ----
  #include <sys/param.h>
  #include <grp.h>
  #include <pwd.h>
+ #ifdef _AIX
+ #include <rpc/rpctypes.h>
+ #else
  #include <rpc/types.h>
+ #endif
  #include "nfsc_err.h"
  #include "machdep.h"
  
***************
*** 52,57 ****
--- 56,62 ----
  	register length=0, i=0;
  	register struct group *gp;
  	static rpc_gid_t grps[NGROUPS];
+ 
  	*status = 0;
  
  	setgrent();
*** ref/nfsc_cmds.ct	Sun Aug  9 12:48:56 1987
--- nfsc_cmds.ct	Fri Aug  9 08:50:02 1991
***************
*** 30,36 ****
  	request nfsc_uflush, "Flush a user's mappings",
  		uflush;
  
! # Generic -- unrelated to test1
  
  	request	ss_list_requests, "List available requests.",
  		list_requests, lr, "?";
--- 30,40 ----
  	request nfsc_uflush, "Flush a user's mappings",
  		uflush;
  
! 	request	credentials_add, "Add a user to the credentials database",
! 		adduser;
! 
! 	request	credentials_delete, "Delete a user from the credentials database",
! 		deluser;
  
  	request	ss_list_requests, "List available requests.",
  		list_requests, lr, "?";
*** ref/nfsc_err.et	Sun Aug  9 12:49:10 1987
--- nfsc_err.et	Fri Aug  9 08:55:36 1991
***************
*** 5,8 ****
--- 5,9 ----
  ec	ETOOMANYGRPS, "Too many groups in groups file"
  ec	ENOMATCH, "No match"
  ec	ENOTDIGIT, "Argument is not numeric"
+ ec	ECANTSTORE, "Unable to write credentials file"
  end
*** ref/nfsc.c	Thu Nov  8 15:33:19 1990
--- nfsc.c	Fri Aug  9 09:13:55 1991
***************
*** 8,15 ****
   */
  
  #ifndef lint
! static char *rcsid_nfsc_c = "$Header: /source/bsd-4.3/common/usr.etc/nfsc/RCS/nfsc.c,v 1.7 90/11/08 15:32:23 probe Exp $";
! #endif lint
  
  #include <stdio.h>
  #include <ss/ss.h>
--- 8,15 ----
   */
  
  #ifndef lint
! static char *rcsid_nfsc_c = "$Header: nfsc.c,v 1.7 90/11/08 15:32:23 probe Exp $";
! #endif
  
  #include <stdio.h>
  #include <ss/ss.h>
***************
*** 26,31 ****
--- 26,37 ----
  #include <string.h>
  #include <errno.h>
  #include <nfs/nfs_mapctl.h>
+ #include <ndbm.h>
+ #include <dbmcred.h>
+ #include <sys/file.h>
+ #ifndef CREDENTIALS
+ #define CREDENTIALS	"/usr/etc/credentials"
+ #endif
  
  extern char *getloginbyuid();
  extern char *getgroupbygid();
***************
*** 48,54 ****
  
  	init_nfsc_err_tbl();
  
! 	ss_idx = ss_create_invocation("nfsc", "1.0", (char *)NULL,
  				       &nfsc_cmds, &code);
  	if (code) {
  		ss_perror(ss_idx, code, "creating invocation");
--- 54,60 ----
  
  	init_nfsc_err_tbl();
  
! 	ss_idx = ss_create_invocation("nfsc", "1.1", (char *)NULL,
  				       &nfsc_cmds, &code);
  	if (code) {
  		ss_perror(ss_idx, code, "creating invocation");
***************
*** 90,98 ****
  {
    	register struct authunix_parms *credp = &acred;
  	int status = 0;
- #ifdef notdef
- 	int bflag = 0;
- #endif notdef
  	rpc_uid_t uid, cuid = (uid_t)-2;
  
  	struct sockaddr_in sin;
--- 96,101 ----
***************
*** 177,183 ****
  	if (nfsmapctl (NFSMC_SET, (char *) &sin, sizeof (sin),
  		           uid, credp) < 0) {
  		if (errno == ESRCH) errno = ENOMATCH;
! 		perror("nfsmapctl");
  	} else {
  		/* should add something to tables.. */
  		printf("add: ");
--- 180,186 ----
  	if (nfsmapctl (NFSMC_SET, (char *) &sin, sizeof (sin),
  		           uid, credp) < 0) {
  		if (errno == ESRCH) errno = ENOMATCH;
! 		com_err ("nfsmapctl", errno, "setting map");
  	} else {
  		/* should add something to tables.. */
  		printf("add: ");
***************
*** 412,416 ****
--- 415,489 ----
  			(*userp)->pw_name = buf;
  		}
  	}
+ 	return 0;
+ }
+ 
+ /* nfsc adduser username uid gid [...] */
+ credentials_add(argc, argv, ss_idx)
+ int argc;
+ register char *argv[];
+ int ss_idx;
+ {
+   DBM *db;
+   register int i;
+   char *user;
+   struct dbmcred cr;
+   datum k,d;
+ 
+   if (argc < 4)
+     return ENOTENOUGHARGS;
+   if ((db = dbm_open(CREDENTIALS, O_RDWR, 0666)) == 0)
+     {
+       fprintf (stderr, "nfsc: Unable to open credentials database %s.\n",
+ 	       CREDENTIALS);
+       return ECANTSTORE;
+     }
+   user = argv[1];
+   cr.uid = atoi(argv[2]);
+   if (cr.uid == 0)
+     fprintf (stderr, "Warning: user \"%s\" has uid 0.\n");
+   cr.gid = atoi(argv[3]);
+   cr.glen = argc - 4;
+   for (i = 4; i < argc; i++)
+     cr.gids[i-4] = atoi(argv[i]);
+   k.dptr = user;
+   k.dsize = strlen(user);
+   d.dptr = (char *)&cr;
+   d.dsize = sizeof(cr);
+   if (dbm_store(db, k, d, DBM_REPLACE))
+     {
+       dbm_close(db);
+       ss_error (ss_idx, ECANTSTORE, "adding user %s", user);
+       return ECANTSTORE;
+     }
+   dbm_close(db);
+   return 0;
+ }
+ 
+ credentials_delete(argc, argv, ss_idx)
+ int argc;
+ register char *argv[];
+ int ss_idx;
+ {
+   DBM *db;
+   datum k;
+ 
+   if (argc < 2)
+     return ENOTENOUGHARGS;
+   if ((db = dbm_open(CREDENTIALS, O_RDWR, 0666)) == 0)
+     {
+       fprintf (stderr, "nfsc: Unable to open credentials database %s.\n",
+ 	       CREDENTIALS);
+       return ECANTSTORE;
+     }
+   k.dptr = argv[1];
+   k.dsize = strlen(argv[1]);
+   if (dbm_delete (db, k))
+     {
+       dbm_close(db);
+       ss_error (ss_idx, ECANTSTORE, "deleting user %s", argv[1]);
+       return ECANTSTORE;
+     }
+   dbm_close(db);
    return 0;
  }
*** ref/nfsc.8	Sun Aug  9 12:49:11 1987
--- nfsc.8	Fri Aug  9 10:18:16 1991
***************
*** 43,48 ****
--- 43,60 ----
  \fBdelete\fP \fIhost\fP \fIforeign-user\fP
  Deletes a mapping from \fIforeign-user\fP on \fIhost\fP if one exists.
  .TP
+ \fBadduser\fP \fIuser\fP \fIuid\fP \fIgid\fP [\fIgroup\fP...]
+ Add user
+ .I user
+ to the credentials database used by
+ .I rpc.mountd
+ with the indicated user ID, group ID, and group membership.
+ .TP
+ \fBdeluser\fP \fIuser\fP
+ Delete user
+ .I user
+ from the credentials database.
+ .TP
  \fBlist\fP \fB \fP
  Lists all mappings.  This may require read access to /dev/kmem (nfsc can
  be safely installed as setgid kmem).

home help back first fref pref prev next nref lref last post