Mercurial > dropbear
comparison scp.c @ 299:740e782679be ucc-axis-hack
Various changes to compile+kind of run on UCC's axis board.
Note that fprintf(stdin -> printf( accounts for many of the changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 25 Mar 2006 12:57:09 +0000 |
parents | 161557a9dde8 |
children | 973fccb59ea4 |
comparison
equal
deleted
inserted
replaced
266:e37b160c414c | 299:740e782679be |
---|---|
142 do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc) | 142 do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc) |
143 { | 143 { |
144 int pin[2], pout[2], reserved[2]; | 144 int pin[2], pout[2], reserved[2]; |
145 | 145 |
146 if (verbose_mode) | 146 if (verbose_mode) |
147 fprintf(stderr, | 147 printf( |
148 "Executing: program %s host %s, user %s, command %s\n", | 148 "Executing: program %s host %s, user %s, command %s\n", |
149 ssh_program, host, | 149 ssh_program, host, |
150 remuser ? remuser : "(unspecified)", cmd); | 150 remuser ? remuser : "(unspecified)", cmd); |
151 | 151 |
152 /* | 152 /* |
156 pipe(reserved); | 156 pipe(reserved); |
157 | 157 |
158 /* Create a socket pair for communicating with ssh. */ | 158 /* Create a socket pair for communicating with ssh. */ |
159 if (pipe(pin) < 0 || pipe(pout) < 0) | 159 if (pipe(pin) < 0 || pipe(pout) < 0) |
160 { | 160 { |
161 fprintf(stderr, "Fatal error: pipe: %s\n", strerror(errno)); | 161 printf( "Fatal error: pipe: %s\n", strerror(errno)); |
162 exit(1); | 162 exit(1); |
163 } | 163 } |
164 | 164 |
165 /* Free the reserved descriptors. */ | 165 /* Free the reserved descriptors. */ |
166 close(reserved[0]); | 166 close(reserved[0]); |
167 close(reserved[1]); | 167 close(reserved[1]); |
168 | 168 |
169 // uClinux needs to build the args here before vforking, | |
170 // otherwise we do it later on. | |
171 #ifdef __uClinux__ | |
172 args.list[0] = ssh_program; | |
173 if (remuser != NULL) | |
174 addargs(&args, "-l%s", remuser); | |
175 addargs(&args, "%s", host); | |
176 addargs(&args, "%s", cmd); | |
177 #endif /* __uClinux__ */ | |
178 | |
169 /* Fork a child to execute the command on the remote host using ssh. */ | 179 /* Fork a child to execute the command on the remote host using ssh. */ |
180 #ifdef __uClinux__ | |
181 do_cmd_pid = vfork(); | |
182 #else | |
170 do_cmd_pid = fork(); | 183 do_cmd_pid = fork(); |
184 #endif /* __uClinux__ */ | |
171 if (do_cmd_pid == 0) { | 185 if (do_cmd_pid == 0) { |
172 /* Child. */ | 186 /* Child. */ |
173 close(pin[1]); | 187 close(pin[1]); |
174 close(pout[0]); | 188 close(pout[0]); |
175 dup2(pin[0], 0); | 189 dup2(pin[0], 0); |
176 dup2(pout[1], 1); | 190 dup2(pout[1], 1); |
177 close(pin[0]); | 191 close(pin[0]); |
178 close(pout[1]); | 192 close(pout[1]); |
179 | 193 |
194 #ifndef __uClinux__ | |
180 args.list[0] = ssh_program; | 195 args.list[0] = ssh_program; |
181 if (remuser != NULL) { | 196 if (remuser != NULL) { |
182 addargs(&args, "-l"); | 197 addargs(&args, "-l"); |
183 addargs(&args, "%s", remuser); | 198 addargs(&args, "%s", remuser); |
184 } | 199 } |
185 addargs(&args, "%s", host); | 200 addargs(&args, "%s", host); |
186 addargs(&args, "%s", cmd); | 201 addargs(&args, "%s", cmd); |
202 #endif | |
187 | 203 |
188 execvp(ssh_program, args.list); | 204 execvp(ssh_program, args.list); |
189 perror(ssh_program); | 205 perror(ssh_program); |
190 exit(1); | 206 exit(1); |
191 } else if (do_cmd_pid == -1) { | 207 } else if (do_cmd_pid == -1) { |
192 fprintf(stderr, "Fatal error: fork: %s\n", strerror(errno)); | 208 printf( "Fatal error: fork: %s\n", strerror(errno)); |
193 exit(1); | 209 exit(1); |
194 } | 210 } |
211 | |
212 #if 0 //__uClinux__ | |
213 /* clean up command */ | |
214 /* pop cmd */ | |
215 free(args->list[--args->num]); | |
216 args->list[args->num]=NULL; | |
217 /* pop host */ | |
218 free(args->list[--args->num-1]); | |
219 args->list[args->num]=NULL; | |
220 /* pop user */ | |
221 if (remuser != NULL) { | |
222 free(args->list[--args->num-1]); | |
223 args->list[args->num]=NULL; | |
224 } | |
225 #endif /* __uClinux__ */ | |
226 | |
195 /* Parent. Close the other side, and return the local side. */ | 227 /* Parent. Close the other side, and return the local side. */ |
196 close(pin[0]); | 228 close(pin[0]); |
197 *fdout = pin[1]; | 229 *fdout = pin[1]; |
198 close(pout[1]); | 230 close(pout[1]); |
199 *fdin = pout[0]; | 231 *fdin = pout[0]; |
318 } | 350 } |
319 argc -= optind; | 351 argc -= optind; |
320 argv += optind; | 352 argv += optind; |
321 | 353 |
322 if ((pwd = getpwuid(userid = getuid())) == NULL) { | 354 if ((pwd = getpwuid(userid = getuid())) == NULL) { |
323 fprintf(stderr, "unknown user %u", (u_int) userid); | 355 printf( "unknown user %u", (u_int) userid); |
324 } | 356 } |
325 | 357 |
326 #ifdef PROGRESS_METER | 358 #ifdef PROGRESS_METER |
327 if (!isatty(STDERR_FILENO)) | 359 if (!isatty(STDERR_FILENO)) |
328 showprogress = 0; | 360 showprogress = 0; |
449 ssh_options, host, cmd, src, | 481 ssh_options, host, cmd, src, |
450 tuser ? tuser : "", tuser ? "@" : "", | 482 tuser ? tuser : "", tuser ? "@" : "", |
451 thost, targ); | 483 thost, targ); |
452 } | 484 } |
453 if (verbose_mode) | 485 if (verbose_mode) |
454 fprintf(stderr, "Executing: %s\n", bp); | 486 printf( "Executing: %s\n", bp); |
455 (void) system(bp); | 487 (void) system(bp); |
456 (void) xfree(bp); | 488 (void) xfree(bp); |
457 } else { /* local to remote */ | 489 } else { /* local to remote */ |
458 if (remin == -1) { | 490 if (remin == -1) { |
459 len = strlen(targ) + CMDNEEDS + 20; | 491 len = strlen(targ) + CMDNEEDS + 20; |
485 bp = xmalloc(len); | 517 bp = xmalloc(len); |
486 (void) snprintf(bp, len, "exec %s%s%s %s %s", _PATH_CP, | 518 (void) snprintf(bp, len, "exec %s%s%s %s %s", _PATH_CP, |
487 iamrecursive ? " -r" : "", pflag ? " -p" : "", | 519 iamrecursive ? " -r" : "", pflag ? " -p" : "", |
488 argv[i], argv[argc - 1]); | 520 argv[i], argv[argc - 1]); |
489 if (verbose_mode) | 521 if (verbose_mode) |
490 fprintf(stderr, "Executing: %s\n", bp); | 522 printf( "Executing: %s\n", bp); |
491 if (system(bp)) | 523 if (system(bp)) |
492 ++errs; | 524 ++errs; |
493 (void) xfree(bp); | 525 (void) xfree(bp); |
494 continue; | 526 continue; |
495 } | 527 } |
582 #define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) | 614 #define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) |
583 snprintf(buf, sizeof buf, "C%04o %lld %s\n", | 615 snprintf(buf, sizeof buf, "C%04o %lld %s\n", |
584 (u_int) (stb.st_mode & FILEMODEMASK), | 616 (u_int) (stb.st_mode & FILEMODEMASK), |
585 (int64_t)stb.st_size, last); | 617 (int64_t)stb.st_size, last); |
586 if (verbose_mode) { | 618 if (verbose_mode) { |
587 fprintf(stderr, "Sending file modes: %s", buf); | 619 printf( "Sending file modes: %s", buf); |
588 } | 620 } |
589 (void) atomicio(vwrite, remout, buf, strlen(buf)); | 621 (void) atomicio(vwrite, remout, buf, strlen(buf)); |
590 if (response() < 0) | 622 if (response() < 0) |
591 goto next; | 623 goto next; |
592 if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) { | 624 if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) { |
660 } | 692 } |
661 } | 693 } |
662 (void) snprintf(path, sizeof path, "D%04o %d %.1024s\n", | 694 (void) snprintf(path, sizeof path, "D%04o %d %.1024s\n", |
663 (u_int) (statp->st_mode & FILEMODEMASK), 0, last); | 695 (u_int) (statp->st_mode & FILEMODEMASK), 0, last); |
664 if (verbose_mode) | 696 if (verbose_mode) |
665 fprintf(stderr, "Entering directory: %s", path); | 697 printf( "Entering directory: %s", path); |
666 (void) atomicio(vwrite, remout, path, strlen(path)); | 698 (void) atomicio(vwrite, remout, path, strlen(path)); |
667 if (response() < 0) { | 699 if (response() < 0) { |
668 closedir(dirp); | 700 closedir(dirp); |
669 return; | 701 return; |
670 } | 702 } |
1049 } | 1081 } |
1050 | 1082 |
1051 void | 1083 void |
1052 usage(void) | 1084 usage(void) |
1053 { | 1085 { |
1054 (void) fprintf(stderr, | 1086 (void) printf( |
1055 "usage: scp [-pqrvBC1246] [-F config] [-S program] [-P port]\n" | 1087 "usage: scp [-pqrvBC1246] [-F config] [-S program] [-P port]\n" |
1056 " [-c cipher] [-i identity] [-l limit] [-o option]\n" | 1088 " [-c cipher] [-i identity] [-l limit] [-o option]\n" |
1057 " [[user@]host1:]file1 [...] [[user@]host2:]file2\n"); | 1089 " [[user@]host1:]file1 [...] [[user@]host2:]file2\n"); |
1058 exit(1); | 1090 exit(1); |
1059 } | 1091 } |
1075 (void) fprintf(fp, "\n"); | 1107 (void) fprintf(fp, "\n"); |
1076 (void) fflush(fp); | 1108 (void) fflush(fp); |
1077 | 1109 |
1078 if (!iamremote) { | 1110 if (!iamremote) { |
1079 va_start(ap, fmt); | 1111 va_start(ap, fmt); |
1080 vfprintf(stderr, fmt, ap); | 1112 vprintf( fmt, ap); |
1081 va_end(ap); | 1113 va_end(ap); |
1082 fprintf(stderr, "\n"); | 1114 printf( "\n"); |
1083 } | 1115 } |
1084 } | 1116 } |
1085 | 1117 |
1086 void | 1118 void |
1087 verifydir(char *cp) | 1119 verifydir(char *cp) |
1121 } | 1153 } |
1122 } | 1154 } |
1123 } while (*++cp); | 1155 } while (*++cp); |
1124 return (1); | 1156 return (1); |
1125 | 1157 |
1126 bad: fprintf(stderr, "%s: invalid user name\n", cp0); | 1158 bad: printf( "%s: invalid user name\n", cp0); |
1127 return (0); | 1159 return (0); |
1128 } | 1160 } |
1129 | 1161 |
1130 BUF * | 1162 BUF * |
1131 allocbuf(BUF *bp, int fd, int blksize) | 1163 allocbuf(BUF *bp, int fd, int blksize) |