[7809] in Athena Bugs

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

attach patches...

daemon@ATHENA.MIT.EDU (vanharen@ATHENA.MIT.EDU)
Fri Jul 26 11:38:27 1991

From: vanharen@ATHENA.MIT.EDU
Date: Fri, 26 Jul 91 11:38:30 -0400
To: bugs@ATHENA.MIT.EDU, probe@ATHENA.MIT.EDU


Two of the suggestions for this release (from the software-suggestions
meeting) were options to attach to allow a list of lockers to be read
from stdin, and an interactive switch (ie, ask the user before attaching
or detaching the lockers in the list).  The second is most useful for
doing  "detach -i -a",  which will go through the list of lockers
currently attached and ask you if you want to detach each of them.

The new switches are  "-i" or "-interactive",  and "-stdin" or "--".

The diffs below implement these suggestions.  These diffs are against
the 7.3 code in the /source tree.

The patch involves changing only four files (attach.c, detach.c,
attach.h, main.c).  The patch to the fifth file (util.c) is to correct a
typo.

I realize this is too late for this release, but maybe next release?

The patches below were tested on vax and rt.  I can't test it on the
other platforms since I don't have root on any other platforms that are
running 7.3 (need to chmod and chown "attach" to test it).

							-C.

==============================================================================

diff -rc /source/athena/athena.bin/attach/attach.c ./attach.c
*** /source/athena/athena.bin/attach/attach.c	Mon Jul  1 09:47:11 1991
--- ./attach.c	Fri Jul 26 11:27:50 1991
***************
*** 16,21 ****
--- 16,42 ----
  extern int mul_attach();
  
  /*
+  * Ask (if interactive) whether to really attach filesystem.
+  */
+ 
+ static int interact(name)
+     const char *name;
+ {
+     char *ptr, buf[BUFSIZ];
+ 
+     if (!interactive)
+ 	return 1;
+     clearerr(stdin);
+     fprintf(stdout, "%s: attach %s? ", progname, name);
+     fgets(buf, BUFSIZ, stdin);
+     for (ptr = buf; *ptr != NULL  &&  isspace(*ptr); ptr++);
+     if (*ptr == 'y' || *ptr == 'Y')
+ 	return 1;
+     return 0;
+ }
+ 
+ 
+ /*
   * Attempt to attach a filesystem.  Lookup the name with Hesiod as
   * necessary, and try all possible results in order.  Also handles
   * the explicit flag for explicitly defined hostname/directory
***************
*** 138,143 ****
--- 159,173 ----
  
      /* Note: attachtab is still locked at this point */
      
+     if (!interact(name)) {
+ 	    start_critical_code();
+ 	    put_attachtab();
+ 	    unlock_attachtab();
+ 	    free_attachtab();
+ 	    end_critical_code();
+ 	    return(SUCCESS);
+     }
+ 
      /* We don't really care about ANY of the values besides status */
      at.status = STATUS_ATTACHING;
      at.explicit = explicit;


diff -rc /source/athena/athena.bin/attach/attach.h ./attach.h
*** /source/athena/athena.bin/attach/attach.h	Mon Jul  1 09:47:18 1991
--- ./attach.h	Wed Jul 24 11:41:43 1991
***************
*** 330,336 ****
  extern int verbose, debug_flag, map_anyway, do_nfsid, print_path, explicit;
  extern int owner_check, owner_list, override, keep_mount;
  extern int error_status, force, lock_filesystem, lookup, euid, clean_detach;
! extern int exp_mntpt, exp_allow;
  #ifdef ZEPHYR
  extern int use_zephyr;
  #endif /* ZEPHYR */
--- 330,336 ----
  extern int verbose, debug_flag, map_anyway, do_nfsid, print_path, explicit;
  extern int owner_check, owner_list, override, keep_mount;
  extern int error_status, force, lock_filesystem, lookup, euid, clean_detach;
! extern int exp_mntpt, exp_allow, interactive;
  #ifdef ZEPHYR
  extern int use_zephyr;
  #endif /* ZEPHYR */


diff -rc /source/athena/athena.bin/attach/detach.c ./detach.c
*** /source/athena/athena.bin/attach/detach.c	Mon Jul  1 09:47:23 1991
--- ./detach.c	Fri Jul 26 11:27:47 1991
***************
*** 12,17 ****
--- 12,38 ----
  #include <string.h>
  
  /*
+  * Ask (if interactive) whether to really detach filesystem.
+  */
+ 
+ static int interact(name)
+     const char *name;
+ {
+     char *ptr, buf[BUFSIZ];
+ 
+     if (!interactive)
+ 	return 1;
+     clearerr(stdin);
+     printf("%s: detach %s? ", progname, name);
+     fgets(buf, BUFSIZ, stdin);
+     for (ptr = buf; *ptr != NULL  &&  isspace(*ptr); ptr++);
+     if (*ptr == 'y' || *ptr == 'Y')
+ 	return 1;
+     return 0;
+ }
+ 
+ 
+ /*
   * Detach the filesystem called name.
   */
  
***************
*** 67,75 ****
  
      /* Note: attachtab still locked at this point */
      
-     start_critical_code();
      if (clean_detach) {
  	    if (clean_attachtab(atp)) {
  		    put_attachtab();
  		    unlock_attachtab();
  		    free_attachtab();
--- 88,96 ----
  
      /* Note: attachtab still locked at this point */
      
      if (clean_detach) {
  	    if (clean_attachtab(atp)) {
+     		    start_critical_code();
  		    put_attachtab();
  		    unlock_attachtab();
  		    free_attachtab();
***************
*** 80,85 ****
--- 101,117 ----
  	     * If we fall through, it means we should detach the filesystem
  	     */
      }
+ 
+     if (!interact(name)) {
+ 	    start_critical_code();
+ 	    put_attachtab();
+ 	    unlock_attachtab();
+ 	    free_attachtab();
+ 	    end_critical_code();
+ 	    return(SUCCESS);
+     }
+ 
+     start_critical_code();
      if (atp->status == STATUS_ATTACHED) {
  	    if (override) {	/* Override _all_ owners and detach */
  		    atp->nowners = 0;


diff -rc /source/athena/athena.bin/attach/main.c ./main.c
*** /source/athena/athena.bin/attach/main.c	Mon Jul  1 09:47:25 1991
--- ./main.c	Fri Jul 26 10:43:21 1991
***************
*** 15,20 ****
--- 15,21 ----
  int verbose = 1, debug_flag = 0, map_anyway = 1, do_nfsid = 1;
  int print_path = 0, explicit = 0, owner_check = 0, override = 0;
  int owner_list = 1, clean_detach = 0, exp_allow = 1, exp_mntpt = 1;
+ int interactive = 0;
  
  /* real userid of proces, effective userid of process, userid used
     for attachtab manipulation */
***************
*** 416,421 ****
--- 417,425 ----
  {
      int gotname, i;
      int print_host = 0;
+     char buf[BUFSIZ];
+     int argcnt = 0;
+     char **argval;
  
      static struct command_list options[] = {
  	{ "-verbose", "-v" },
***************
*** 449,454 ****
--- 453,460 ----
  	{ "-lock", "-L" },
  	{ "-user", "-U" },
  	{ "-host", "-H" },
+ 	{ "-interactive", "-i" },
+ 	{ "-stdin", "--" },
  	{ 0, 0 }};
  
      read_config_file(ATTACHCONFFILE);
***************
*** 472,477 ****
--- 478,485 ----
      if (argc == 1)
  	return (attach_print(0));
      
+     argval = (char **) malloc(sizeof(char **));
+ 
      for (i=1;i<argc;i++) {
  	if (*argv[i] == '-') {
  	    switch (internal_getopt(argv[i], options)) {
***************
*** 503,508 ****
--- 511,517 ----
  		if (i == argc-1) {
  			fprintf(stderr, "%s: No mount point specified\n", 
  				progname);
+ 			free(argval);
  			return (ERR_BADARGS);
  		}
  		if (exp_mntpt || trusted_user(real_uid)) {
***************
*** 529,534 ****
--- 538,546 ----
  	    case 'a':
  		map_anyway = 0;
  		break;
+ 	    case 'i':
+ 		interactive = 1;
+ 		break;
  #ifdef ZEPHYR
  	    case 'z':
  		use_zephyr = 1;
***************
*** 550,555 ****
--- 562,568 ----
  	    case 't':
  		if (i == argc-1) {
  		    fprintf(stderr, "%s: No filesystem type specified\n", progname);
+ 		    free(argval);
  		    return (ERR_BADARGS);
  		}
  		filsys_type = argv[++i];
***************
*** 557,562 ****
--- 570,576 ----
  	    case 'o':
  		if (i == argc-1) {
  		    fprintf(stderr, "%s: No mount options specified\n", progname);
+ 		    free(argval);
  		    return (ERR_BADARGS);
  		}
  		mount_options = argv[++i];
***************
*** 564,569 ****
--- 578,584 ----
  	    case 's':
  		if (i == argc-1) {
  		    fprintf(stderr, "%s: No spoof host specified\n", progname);
+ 		    free(argval);
  		    return (ERR_BADARGS);
  		}
  		spoofhost = argv[++i];
***************
*** 612,619 ****
--- 627,646 ----
  	    case 'H':
  		print_host++;
  		break;
+ 	    case '-':
+ 		while (scanf("%s", buf) != EOF) {
+ 		  argcnt++;
+ 		  argval = (char **) realloc(argval,
+ 					     (argcnt+1)*(sizeof(char **)));
+ 		  argval[argcnt] = strdup(buf);
+ 		}
+ 		argcnt++;
+ 		error_status = attachcmd(argcnt, argval);
+ 		gotname = argcnt;
+ 		break;
  	    default:
  		fprintf(stderr, "%s: Unknown switch %s\n", progname, argv[i]);
+ 		free(argval);
  		return (ERR_BADARGS);		
  	    }
  	    continue;
***************
*** 637,642 ****
--- 664,670 ----
      zephyr_sub(0);
  #endif /* ZEPHYR */
  
+     free(argval);
      if (gotname == 1)
  	return (error_status);
      if (gotname > 1)
***************
*** 652,658 ****
      char *argv[];
  {
      int gotname, i;
!     int	dohost;
      static struct command_list options[] = {
  	{ "-verbose", "-v" },
  	{ "-quiet", "-q" },
--- 680,689 ----
      char *argv[];
  {
      int gotname, i;
!     char buf[BUFSIZ];
!     int argcnt = 0;
!     char **argval;
!     int	dohost, doall;
      static struct command_list options[] = {
  	{ "-verbose", "-v" },
  	{ "-quiet", "-q" },
***************
*** 674,679 ****
--- 705,712 ----
  	{ "-user", "-U" },
  	{ "-clean", "-C" },
  	{ "-lint", "-L" },
+ 	{ "-stdin", "--" },
+ 	{ "-interactive", "-i" },
  	{ 0, 0}};
  
      check_root_privs(progname);
***************
*** 686,693 ****
--- 719,728 ----
      force = 0;
      override = 0;
      dohost = 0;
+     doall = 0;
      error_status = ERR_NONE;
      filsys_type = NULL;
+     argval = (char **) malloc(sizeof(char **));
      
      for (i=1;i<argc;i++) {
  	if (*argv[i] == '-') {
***************
*** 731,747 ****
  		if (i == argc-1) {
  		    fprintf(stderr, "%s: No filesystem type specified\n", 
  			    progname);
  		    return (ERR_BADARGS);
  		}
  		filsys_type = argv[++i];
  		break;
  	    case 'a':
! 		detach_all();
  		gotname = 2;
  		break;
  	    case 's':
  		if (i == argc-1) {
  		    fprintf(stderr, "%s: No spoof host specified\n", progname);
  		    return (ERR_BADARGS);
  		}
  		spoofhost = argv[++i];
--- 766,787 ----
  		if (i == argc-1) {
  		    fprintf(stderr, "%s: No filesystem type specified\n", 
  			    progname);
+ 		    free(argval);
  		    return (ERR_BADARGS);
  		}
  		filsys_type = argv[++i];
  		break;
+ 	    case 'i':
+ 		interactive = 1;
+ 		break;
  	    case 'a':
! 		doall = 1;
  		gotname = 2;
  		break;
  	    case 's':
  		if (i == argc-1) {
  		    fprintf(stderr, "%s: No spoof host specified\n", progname);
+ 		    free(argval);
  		    return (ERR_BADARGS);
  		}
  		spoofhost = argv[++i];
***************
*** 760,765 ****
--- 800,806 ----
  			if (!argv[i]) {
  				fprintf(stderr, "%s: Username required with -U.\n",
  					progname);
+ 				free(argval);
  				return (ERR_BADARGS);
  			}
  			owner_uid = parse_username(argv[i]);
***************
*** 775,782 ****
--- 816,835 ----
  		lint_attachtab();
  		gotname = 1;
  		break;
+ 	case '-':
+ 		while (scanf("%s", buf) != EOF) {
+ 		  argcnt++;
+ 		  argval = (char **) realloc(argval,
+ 					     (argcnt+1)*(sizeof(char **)));
+ 		  argval[argcnt] = strdup(buf);
+ 		}
+ 		argcnt++;
+ 		error_status = detachcmd(argcnt, argval);
+ 		gotname = argcnt;
+ 		break;
  	default:
  		fprintf(stderr, "%s: Unknown switch %s\n", progname, argv[i]);
+ 		free(argval);
  		return (ERR_BADARGS);
  	    }
  	    continue;
***************
*** 789,799 ****
--- 842,856 ----
  	dohost = 0;
      }
  
+     if (doall)
+ 	detach_all();
+ 
      /* Flush Zephyr unsubscriptions */
  #ifdef ZEPHYR
      zephyr_unsub(0);
  #endif /* ZEPHYR */
      
+     free(argval);
      if (gotname == 1)
  	return (error_status);
      if (gotname > 1)


diff -rc /source/athena/athena.bin/attach/util.c ./util.c
*** /source/athena/athena.bin/attach/util.c	Tue Jul  9 20:49:18 1991
--- ./util.c	Fri Jul 26 11:01:15 1991
***************
*** 448,454 ****
      unlink(filename);
      fd = open(filename, O_CREAT, 0644);
      if (!fd) {
! 	    fprintf(stderr,"Can't open %s: %s\n", attachtab_fn,
  		    sys_errlist[errno]);
  	    fprintf(stderr, abort_msg);
  	    exit(ERR_FATAL);
--- 448,454 ----
      unlink(filename);
      fd = open(filename, O_CREAT, 0644);
      if (!fd) {
! 	    fprintf(stderr,"Can't open %s: %s\n", filename,
  		    sys_errlist[errno]);
  	    fprintf(stderr, abort_msg);
  	    exit(ERR_FATAL);

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