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