1: # include "defs.h"
   2: 
   3: /* global variables */
   4: struct userinfo status;
   5: 
   6: /* netcp - copy with remote machines */
   7: main(argc,argv)
   8:   char **argv;
   9:     {
  10:     char rcmd[BUFSIZ], acmd[BUFSIZ], *sn;
  11:     char mchto, mchfrom, sfnto[FNS], sfnfrom[FNS];
  12: 
  13:     argv[argc] = 0;
  14:     if(argc < 3)goto usage;
  15:     argv++, argc--;
  16:     while(argv[0][0] == '-'){
  17:         switch(argv[0][1]){
  18:         case 'b':   status.nonotify++; break;
  19:         case 'f':   status.force++; break;
  20:         case 'l':   harg(status.login,&argc,&argv); break;
  21:         case 'n':   status.nowrite++; break;
  22:         case 'p':   harg(status.mpasswd,&argc,&argv); break;
  23:         case 'q':   status.quiet++; break;
  24:         default:    fprintf(stderr,"Unknown option %s\n",argv[0]);
  25:                 break;
  26:         }
  27:         argc--;argv++;
  28:         }
  29:     if(argc > 2)goto usage;
  30:     sprintf(rcmd,"netcp %s %s",argv[0],argv[1]);
  31:     mchfrom = analfile(sfnfrom,argv[0]);
  32:     mchto =   analfile(sfnto,argv[1]);
  33:     if(mchfrom  == 0 || mchto  == 0){
  34:         fprintf(stderr,"Unknown machine\n");
  35:         exit(EX_NOHOST);
  36:     }
  37:     if(sfnfrom[0] == 0 || sfnto[0] == 0){
  38:         fprintf(stderr,"Must specify both file names\n");
  39:         exit(EX_USAGE);
  40:     }
  41:     if(mchfrom == local && mchto == local){
  42:         fprintf(stderr,"Error: both files are on this machine\n");
  43:         exit(EX_USAGE);
  44:         }
  45:     else if(mchfrom == local)
  46:         kexecl(netcmd,"net","-m",longname(mchto), "-o",sfnto,"-s",sfnfrom,
  47:             "-c",rcmd,"cat",0);
  48:     else if(mchto == local){
  49:         kexecl(netcmd,"net","-m",longname(mchfrom), "-r",sfnto,"-i",sfnfrom,
  50:             "-c",rcmd,"cat",0);
  51:         }
  52:     /* remote for both */
  53:     else if(mchto == mchfrom)
  54:         kexecl(netcmd,"net","-m",longname(mchto),"-c",rcmd,"cp",sfnfrom,sfnto,0);
  55:     else {
  56:         /* experimental - still needs debugging */
  57:         fprintf(stderr,
  58:             "Experimental - Machines normally must be the same\n");
  59: 
  60:         /* collect info on the "To Machine" */
  61:         remote = mchto;
  62:         /* get status.login and passwd from .netrc if poss. */
  63:         commandfile();
  64:         if(status.login[0] == 0 || status.mpasswd[0] == 0){
  65:             sn = SnFromUid(getuid());
  66:             if(sn == NULL){
  67:                 fprintf(stderr,"Unknown user\n");
  68:                 exit(EX_OSFILE);
  69:             }
  70:             strcpy(status.localname,sn);
  71:             /* check environ */
  72:             envloginpasswd(remote,status.login,status.mpasswd);
  73:             /* prompt on terminal */
  74:             promptlogin(remote);
  75:         }
  76:         /* should use -q option */
  77:         sprintf(acmd,"%s -l %s -p %s %s %s",
  78:             NETCPCMD,status.login,status.mpasswd,argv[0],argv[1]);
  79: 
  80:         /* send the netcp command to the "From" machine */
  81:         remote = mchfrom;
  82:         status.login[0] = status.mpasswd[0] = 0;
  83:         mexecl(netcmd,"net","-m",longname(mchfrom),"-c",rcmd,acmd,0);
  84:         }
  85:     perror(netcmd);
  86:     fprintf(stderr,"Network is down\n");
  87:     exit(EX_UNAVAILABLE);
  88: usage:
  89:     printf("Usage: netcp [-l ...] [-p ...] [-f] [-n] fromfile tofile\n");
  90:     exit(EX_USAGE);
  91:     }
  92: 
  93: analfile(sfn,addr)
  94: char *sfn;
  95: char *addr;
  96: {
  97:     register char *file;
  98:     char work[FNS], *s, c0,c1,c2,c3,c,colon=0,mch;
  99:     mch = local;
 100:     strcpy(work,addr);
 101:     s = work;
 102:     file = s;
 103:     while(*s){
 104:         if(*s == '/')break;
 105:         if(*s == ':'){
 106:             colon = 1;
 107:             *s++ = 0;
 108:             break;
 109:         }
 110:         s++;
 111:     }
 112:     if(colon){ /* name specified */
 113:         mch = lookup(file);
 114:         if(mch == 0){
 115:             return(mch);
 116:             }
 117:         file = s;
 118:         }
 119:     else {
 120:         s  = file;
 121:         c0 = *s++;
 122:         c1 = *s++;
 123:         c2 = *s++;
 124:         c3 = *s++;
 125:         if(c0 == '/' && c1 != '/' && islower(c1))
 126:             if(c3 == '/')mch = c1;      /* CC name */
 127:     }
 128:     strcpy(sfn,file);
 129:     s = sfn;
 130:     /* check for bad chars in file name */
 131:     while(c = *s++)
 132:         if(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\b')
 133:             err("Invalid character '%c'\n",c);
 134:     return(mch);
 135:     }

Defined functions

analfile defined in line 93; used 2 times
main defined in line 7; never used

Defined variables

status defined in line 4; used 15 times
Last modified: 1980-07-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 819
Valid CSS Valid XHTML 1.0 Strict