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