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