Changeset 1242 for TI05-delivery/trunk
- Timestamp:
- 27/06/06 10:27:28 (15 years ago)
- Location:
- TI05-delivery/trunk
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI05-delivery/trunk/setup.py
r1238 r1242 45 45 server_sources = ['%s/bbftpd/%s' % (bbftpd_home, x) for x in bbftpd_src] + ['./src/python_ext/bbftpd.c'] 46 46 47 bbftpc_src = [ 'bbftp.c',48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 47 bbftpc_src = [ 48 'bbftp_cd.c', 49 'bbftp_get.c', 50 'bbftp_lcd.c', 51 'bbftp_list.c', 52 'bbftp_mget.c', 53 'bbftp_mkdir.c', 54 'bbftp_mput.c', 55 'bbftp_put.c', 56 'bbftp_rm.c', 57 'bbftp_stat.c', 58 'bbftp_statfs.c', 59 'bbftp_dir.c', 60 'bbftp_retr.c', 61 'bbftp_setremotecos.c', 62 'bbftp_setremoteumask.c', 63 'bbftp_store.c', 64 'bbftp_socket.c', 65 'bbftp_utils.c', 66 'connecttoserver.c', 67 'getdatasock.c', 68 'readmessage.c', 69 'sendproto.c', 70 'treatcommand.c', 71 'bbftp_turl.c', 72 'writemessage.c', 73 'setsignals.c', 74 'bbftp_private.c', 75 'bbftp_private_user.c' 76 ] 77 77 78 78 client_sources = ['%s/bbftpc/%s' % (bbftpc_home, x) for x in bbftpc_src] + ['./src/python_ext/bbftpc.c', 79 './src/python_ext/util.c'] 79 './src/python_ext/util.c', 80 './src/python_ext/bbftpc_main.c'] 80 81 81 82 #------------------------------------------------------------------------------------------- -
TI05-delivery/trunk/src/python_ext/bbftpc_main.c
r1241 r1242 21 21 22 22 /** 23 * This is a drop-in replacment for bbftp.c for use with NDG python embedding. 24 * Since it is largely based on the original bbftp code I have retained the original 25 * copyright. Most sections from bbftp.c are not relevent when embedding in python 26 * and have been removed. Support for CASTOR and RFIO has been removed. 23 * This is a drop-in replacment for bbftp.c for use with NDG python 24 * embedding. Together with bbftpc.h and bbftpc_globals.h it contains 25 * all code originally in bbftp.c that is required for the embedded 26 * client. Since it is largely based on the original bbftp code I 27 * have retained the original copyright. Most sections from bbftp.c 28 * are not relevent when embedding in python and have been removed. 29 * Support for ssh, CASTOR and RFIO has been removed. The defines 30 * PRIVATE_AUTH and NDG_PYTHON_EMBED are assumed in this file. 27 31 * 28 32 * @author Stephen Pascoe 29 33 */ 30 34 31 32 #include <bbftp.h> 33 34 #include <errno.h> 35 #include <fcntl.h> 36 #include <netdb.h> 37 #include <netinet/in.h> 38 #include <pwd.h> 39 #include <stdio.h> 40 #include <sys/stat.h> 41 #include <sys/types.h> 42 #include <unistd.h> 43 #if TIME_WITH_SYS_TIME 44 # include <sys/time.h> 45 # include <time.h> 46 #else 47 # if HAVE_SYS_TIME_H 48 # include <sys/time.h> 49 # else 50 # include <time.h> 51 # endif 52 #endif 53 #if HAVE_STRING_H 54 # include <string.h> 55 #endif 56 57 #include <client.h> 58 #include <client_proto.h> 59 #include <common.h> 60 #include <config.h> 61 #include <structures.h> 62 #include <version.h> 63 64 #ifdef WITH_SSL 65 #include <openssl/rsa.h> 66 #endif 67 68 #ifdef WITH_GZIP 69 # include <zlib.h> 70 #endif 71 72 #define SETTOZERO 0 73 #define SETTOONE 1 74 75 #define SSHREMOTECMD "bbftpd -s" 76 #define SSHCMD "ssh -q" 77 78 #ifdef PRIVATE_AUTH 79 #define OPTIONS "qbcde:f:i:l:mno:p:P:r:R:tu:vVw:WD::" 80 #else 81 #define OPTIONS "qbcde:E:f:g:i:I:l:L:mno:p:r:R:sStu:vVw:WD::" 82 #endif 83 /* 84 #endif 85 */ 86 87 int state = SETTOZERO ; 88 /* 89 ** timestamp: 90 ** Every message on standart error and standart output are 91 ** timestamped 92 */ 93 int timestamp = SETTOZERO ; 94 /* 95 ** protocolmin: 96 ** Minimum protocol supportted 97 */ 98 int protocolmin = 2 ; 99 int protocolmax = 3 ; 100 int protocol ; 101 /* 102 ** debug: 103 ** Set to one to print more debugging information 104 */ 105 int debug = SETTOZERO ; 106 /* 107 ** verbose: 108 ** Set to one to print information 109 */ 110 int verbose = SETTOZERO ; 111 /* 112 ** warning: 113 ** Set to one to print warning to stderr 114 */ 115 int warning = SETTOZERO ; 116 /* 117 ** statoutput: 118 ** Set to one for special output 119 */ 120 int statoutput = SETTOZERO ; 121 /* 122 ** globaltrymax: 123 ** Number of try in case or recoverable error 124 */ 125 int globaltrymax = NBTRYMAX ; 126 /* 127 ** newcontrolport: 128 ** Control port to be used 129 */ 130 int newcontrolport = CONTROLPORT ; 131 /* 132 ** usessh: 133 ** Set to one when using ssh to start the remote daemon 134 */ 135 int usessh = SETTOZERO ; 136 /* 137 ** sshbatchmode: 138 ** This is set to non-zero if running in batch mode (that is, password 139 ** and passphrase queries are not allowed). 140 */ 141 int sshbatchmode = SETTOZERO ; 142 /* 143 ** sshchildpid: 144 ** To keep the ssh child pid 145 */ 146 int sshchildpid = SETTOZERO ; 147 /* 148 ** For ssh 149 */ 150 char *sshidentityfile = NULL ; 151 char *sshremotecmd = NULL ; 152 char *sshcmd = NULL ; 153 /* 154 ** usecert: 155 ** Set to one if using certificate authentifaction 156 */ 157 int usecert = SETTOZERO ; 158 /* 159 ** useprivate: 160 ** Set to one if using private authentication 161 */ 162 int useprivate = SETTOZERO ; 163 /* 164 ** privatestr: 165 ** Pointer to a private string used for private authentication 166 ** 167 */ 168 char *privatestr = NULL ; 169 /* 170 ** hisctladdr: 171 ** the remote address 172 */ 173 struct sockaddr_in hisctladdr ; 174 /* 175 ** myctladdr: 176 ** the local address 177 */ 178 struct sockaddr_in myctladdr ; 179 /* 180 ** bbftprc: 181 ** Where to store the bbftprc file 182 */ 183 char *bbftprc = NULL ; 184 /* 185 ** Variable defining the local options : 186 ** 187 ** localumask: 188 ** Local umask taken by the umask command at start and 189 ** modified by the setlocalumask command 190 ** 191 ** localrfio: 192 ** set to one when using rfio for local files 193 ** 194 */ 195 int localumask ; 196 197 char *newcmd = NULL; 198 int remoterfio; 199 int localrfio; 200 /* 201 ** Variables defining both side options : 202 ** 203 ** usetmpfile: 204 ** Set to one when using tmpname for file creation 205 ** 206 ** usegzipcompress: 207 ** Set to one when using tmpname for file creation 208 ** 209 ** keepaccess: 210 ** Set to one when keeping access time and modification 211 ** 212 ** keepmode: 213 ** Set to one when keeping file mode 214 ** 215 ** creatdir: 216 ** Set to one when automatic directory creation is needed 217 */ 218 int sendwinsize = 256 ; 219 int recvwinsize = 256 ; 220 int nbport = 1 ; 221 int ackto = ACKTO; 222 int recvcontrolto = CONTROLSOCKTO; 223 int sendcontrolto = SENDCONTROLTO; 224 int datato = DATASOCKTO; 225 226 /* 227 ** Variables remote side options : 228 ** 229 ** remoterfio: 230 ** Set to one when rfio for remote file 231 ** 232 ** remoteumask: 233 ** if set to zero do not set remote umask 234 ** 235 ** remotecos: 236 ** if not set to zero do set remote cos 237 ** 238 ** remotedir : 239 ** if not set to NULL change dir after connection 240 ** 241 */ 242 int remoteumask = SETTOZERO ; 243 int remotecos = -1 ; 244 char *remotedir = NULL ; 245 /* 246 ** incontrolsock : 247 ** Define the control socket for reading 248 ** outcontrolsock : 249 ** Define the control socket for writing 250 ** 251 ** For normal use : incontrolsock = outcontrolsock 252 */ 253 int incontrolsock ; 254 int outcontrolsock ; 255 /* 256 ** myexitcode : 257 ** Contains the first error code that has to be return when program 258 ** is ended 259 */ 260 int myexitcode = SETTOZERO ; 261 char *hostname = NULL ; 262 struct hostent *hp = NULL ; 263 char *username = NULL ; 264 char *password = NULL ; 265 /* 266 ** mychildren : 267 ** Pointer to the first pid of children 268 */ 269 int *mychildren = NULL ; 270 /* 271 ** nbpidchid : 272 ** Number of pid pointed by mychildren 273 */ 274 int nbpidchild ; 275 276 /* 277 ** Parameters describing the transfer ******************** 278 */ 279 int transferoption = TROPT_TMP | TROPT_DIR | TROPT_MODE | TROPT_ACC; 280 int filemode ; 281 char lastaccess[9] ; 282 char lastmodif[9] ; 283 int buffersizeperstream = 256 ; 284 int requestedstreamnumber ; 285 my64_t filesize ; 286 /* 287 ** curfilename : 288 ** Define the pointer to the current file 289 */ 290 char *curfilename = NULL ; 291 /* 292 ** realfilename : 293 ** Define the pointer to the real file (= curfilename if TROPT_TMP not 294 ** set) 295 */ 296 char *realfilename = NULL ; 297 int *myports = NULL ; 298 int *mysockets = NULL ; 299 char *readbuffer = NULL ; 300 char *compbuffer = NULL ; 301 int resfd = -1 ; 302 /* 303 ** Simulation mode (option -n) 304 */ 305 int simulation_mode = SETTOZERO; 306 /* 307 ** 308 */ 309 int connectionisbroken = SETTOZERO ; 310 311 /* 312 * Range for the ephemeral ports for data connections 35 #include "bbftpc.h" 36 #include "bbftpc_globals.h" 37 38 /** 39 * Reset all global variables to how they were first initialised. 313 40 */ 314 int pasvport_min = 0 ; 315 int pasvport_max = 0 ; 316 317 /** Reset all global variables to how they were first initialised. 318 */ 319 void bbftpc_reset_globals(void) { 41 static void bbftpc_reset_globals(void) { 320 42 321 43 state = SETTOZERO ; … … 371 93 //int nbpidchild ; 372 94 transferoption = TROPT_TMP | TROPT_DIR | TROPT_MODE | TROPT_ACC; 373 filemode ;374 lastaccess[9] ;375 lastmodif[9] ;95 //int filemode ; 96 //char lastaccess[9] ; 97 //char lastmodif[9] ; 376 98 buffersizeperstream = 256 ; 377 99 //int requestedstreamnumber ; … … 391 113 pasvport_max = 0 ; 392 114 393 commandList = NULL;394 first = NULL;395 iterator = NULL;396 115 } 397 116 398 117 399 400 bbftpc_main(int argc, char **argv, char **envp) { 118 static void print_version(void) { 119 printmessage(stdout,CASE_NORMAL,0,timestamp,"bbftp version %s\n",VERSION) ; 120 printmessage(stdout,CASE_NORMAL,0,timestamp,"Compiled with : default port %d\n",CONTROLPORT) ; 121 #ifdef PORT_RANGE 122 printmessage(stdout,CASE_NORMAL,0,timestamp," data ports range = %s \n", PORT_RANGE) ; 123 #endif 124 #ifdef WITH_GZIP 125 printmessage(stdout,CASE_NORMAL,0,timestamp," compression with Zlib-%s\n", zlibVersion()) ; 126 #endif 127 #ifdef WITH_SSL 128 printmessage(stdout,CASE_NORMAL,0,timestamp," encryption with %s \n",SSLeay_version(SSLEAY_VERSION)) ; 129 #endif 130 #ifdef AFS 131 printmessage(stdout,CASE_NORMAL,0,timestamp," AFS authentication \n") ; 132 #endif 133 printmessage(stdout,CASE_NORMAL,0,timestamp," private authentication \n") ; 134 printmessage(stdout,CASE_NORMAL,0,timestamp," Embedded in Python interpreter\n") ; 135 136 printmessage(stdout,CASE_NORMAL,0,timestamp," default number of tries = %d \n",NBTRYMAX) ; 137 printmessage(stdout,CASE_NORMAL,0,timestamp," default sendwinsize = %d Kbytes\n",sendwinsize) ; 138 printmessage(stdout,CASE_NORMAL,0,timestamp," default recvwinsize = %d Kbytes\n",recvwinsize) ; 139 printmessage(stdout,CASE_NORMAL,0,timestamp," default number of stream = %d \n",nbport) ; 140 } 141 142 143 static void print_debug(void) { 144 if (simulation_mode) { 145 printmessage(stdout,CASE_NORMAL,0,timestamp,"** SIMULATION MODE: No data written **\n") ; 146 } 147 printmessage(stdout,CASE_NORMAL,0,timestamp,"Starting parameters -----------------\n") ; 148 printmessage(stdout,CASE_NORMAL,0,timestamp,"number of tries = %d\n",globaltrymax) ; 149 printmessage(stdout,CASE_NORMAL,0,timestamp,"number of streams = %d\n",nbport) ; 150 printmessage(stdout,CASE_NORMAL,0,timestamp,"localumask = %03o\n",localumask) ; 151 printmessage(stdout,CASE_NORMAL,0,timestamp,"remoteumask = %03o\n",remoteumask) ; 152 printmessage(stdout,CASE_NORMAL,0,timestamp,"remotecos = %d\n",remotecos) ; 153 printmessage(stdout,CASE_NORMAL,0,timestamp,"buffersize = %d KB\n",buffersizeperstream) ; 154 printmessage(stdout,CASE_NORMAL,0,timestamp,"sendwinsize = %d KB\n",sendwinsize) ; 155 printmessage(stdout,CASE_NORMAL,0,timestamp,"recvwinsize = %d KB\n",recvwinsize) ; 156 printmessage(stdout,CASE_NORMAL,0,timestamp,"ackto = %d s\n",ackto) ; 157 printmessage(stdout,CASE_NORMAL,0,timestamp,"recvcontrolto = %d s\n",recvcontrolto) ; 158 printmessage(stdout,CASE_NORMAL,0,timestamp,"sendcontrolto = %d s\n",sendcontrolto) ; 159 printmessage(stdout,CASE_NORMAL,0,timestamp,"datato = %d s\n",datato) ; 160 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_DIR ) == TROPT_DIR) ? "createdir" : "nocreatedir") ; 161 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_TMP ) == TROPT_TMP) ? "tmpfile" : "notmpfile") ; 162 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_RFIO ) == TROPT_RFIO) ? "remoterfio" : "noremoterfio") ; 163 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_MODE ) == TROPT_MODE) ? "keepmode" : "nokeepmode") ; 164 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_ACC ) == TROPT_ACC) ? "keepaccess" : "nokeepaccess") ; 165 #ifdef WITH_GZIP 166 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_GZIP ) == TROPT_GZIP) ? "gzip" : "nogzip") ; 167 #endif 168 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_QBSS ) == TROPT_QBSS) ? "qbss" : "noqbss") ; 169 printmessage(stdout,CASE_NORMAL,0,timestamp,"-------------------------------------\n") ; 170 printmessage(stdout,CASE_NORMAL,0,timestamp,"Connection mode ---------------------\n") ; 171 printmessage(stdout,CASE_NORMAL,0,timestamp,"Using standard bbftp mode\n",localumask) ; 172 printmessage(stdout,CASE_NORMAL,0,timestamp,"-------------------------------------\n") ; 173 } 174 175 176 static void close_connection(void) { 177 char minbuffer[MINMESSLEN] ; 178 struct message *msg ; 179 180 msg = (struct message *)minbuffer ; 181 msg->code = MSG_CLOSE_CONN ; 182 msg->msglen = 0 ; 183 /* 184 ** We do not care of the result because this routine is called 185 ** only at the end of the client 186 */ 187 writemessage(outcontrolsock,minbuffer,MINMESSLEN,sendcontrolto,0) ; 188 sleep(1) ; 189 bbftp_close_control() ; 190 } 191 192 193 int bbftpc_main(int argc, char **argv, char **envp) { 401 194 bbftpc_reset_globals(); 402 195 403 196 extern char *optarg; 404 197 extern int optind, opterr, optopt; 405 /* 406 ** Variable set by options 407 */ 408 char *inputfile = NULL ; 409 char *resultfile = NULL ; 410 char *outputfile = NULL ; 411 char *errorfile = NULL ; 412 char *bbftpcmd = NULL ; 413 int background = SETTOZERO ; 414 /* 415 ** For hostname 416 */ 417 int hosttype = 0 ; 418 char *calchostname ; 419 /* 420 ** For local user 421 */ 422 struct passwd *mypasswd ; 423 char *bbftprcfile = NULL ; 424 int fd ; 425 char *carret ; 426 char *startcmd ; 427 int nooption ; 198 /* 199 ** Variable set by options 200 */ 201 char *outputfile = NULL ; 202 char *bbftpcmd = NULL ; 203 /* 204 ** For hostname 205 */ 206 int hosttype = 0 ; 207 char *calchostname ; 208 /* 209 ** For local user 210 */ 211 char *bbftprcfile = NULL ; 212 213 int retcode ; 214 int i, j, k ; 215 int alluse ; 216 char logmessage[1024] ; 217 /* 218 ** Get local umask 219 */ 220 localumask = umask(0) ; 221 /* 222 ** and reset it to the correct value 223 */ 224 umask(localumask) ; 225 /* 226 ** First check for timestamp in order to have a common output 227 */ 228 opterr = 0 ; 229 while ((j = getopt(argc, argv, OPTIONS)) != -1) { 230 switch (j) { 231 case 't' : 232 timestamp = SETTOONE ; 233 break ; 234 } 235 } 236 237 useprivate = SETTOONE ; 238 usessh = SETTOZERO ; 428 239 429 struct stat statbuf ; 430 int retcode ; 431 int i, j, k ; 432 int stderrfd ; 433 int stdoutfd ; 434 int infd ; 435 char calcmaxline[1] ; 436 int maxlen ; 437 int lengthread ; 438 char *buffercmd ; 439 int alluse ; 440 char *tmpsshremotecmd ; 441 char logmessage[1024] ; 442 char minbuffer[MINMESSLEN] ; 443 struct message *msg ; 444 /* 445 ** Get local umask 446 */ 447 localumask = umask(0) ; 448 /* 449 ** and reset it to the correct value 450 */ 451 umask(localumask) ; 452 /* 453 ** First check for timestamp in order to have a common output 454 */ 455 opterr = 0 ; 456 while ((j = getopt(argc, argv, OPTIONS)) != -1) { 457 switch (j) { 458 case 't' :{ 459 timestamp = SETTOONE ; 460 break ; 461 } 462 } 463 } 464 465 useprivate = SETTOONE ; 466 usessh = SETTOZERO ; 467 468 /* 469 ** Check for -v option 470 */ 471 opterr = 0 ; 472 optind = 1 ; 473 while ((j = getopt(argc, argv, OPTIONS)) != -1) { 474 switch (j) { 475 case 'v' :{ 476 printmessage(stdout,CASE_NORMAL,0,timestamp,"bbftp version %s\n",VERSION) ; 477 printmessage(stdout,CASE_NORMAL,0,timestamp,"Compiled with : default port %d\n",CONTROLPORT) ; 240 /* 241 ** Check for -v option 242 */ 243 opterr = 0 ; 244 optind = 1 ; 245 while ((j = getopt(argc, argv, OPTIONS)) != -1) { 246 switch (j) { 247 case 'v' : 248 print_version(); 249 exit(0) ; 250 } 251 } 252 253 /** 254 * @todo replace getopt arguments with python calls. 255 */ 256 257 /* 258 ** Now all the others 259 */ 260 opterr = 0 ; 261 optind = 1 ; 262 while ((j = getopt(argc, argv, OPTIONS)) != -1) { 263 switch (j) { 264 case 'c' : 265 #ifdef WITH_GZIP 266 transferoption = transferoption | TROPT_GZIP ; 267 #else 268 printmessage(stderr,CASE_FATAL_ERROR,7,timestamp,"option -c is not available: bbftp was built without compression utility\n") ; 269 #endif 270 break ; 271 272 case 'd' : 273 debug = 1 ; 274 break ; 275 276 case 'D' : 277 if (optarg) { 278 if ((sscanf(optarg,"%d:%d",&i, &k) == 2) && (i < k)) { 279 pasvport_min = i; pasvport_max = k; 280 } else { 281 printmessage(stderr,CASE_FATAL_ERROR,4,timestamp,"Invalid port range : %s\n",optarg) ; 282 } 283 } else { 478 284 #ifdef PORT_RANGE 479 printmessage(stdout,CASE_NORMAL,0,timestamp," data ports range = %s \n", PORT_RANGE) ;285 sscanf(PORT_RANGE,"%d:%d",&pasvport_min, &pasvport_max) ; 480 286 #endif 481 #ifdef WITH_GZIP 482 printmessage(stdout,CASE_NORMAL,0,timestamp," compression with Zlib-%s\n", zlibVersion()) ; 483 #endif 484 #ifdef WITH_SSL 485 printmessage(stdout,CASE_NORMAL,0,timestamp," encryption with %s \n",SSLeay_version(SSLEAY_VERSION)) ; 486 #endif 487 #ifdef AFS 488 printmessage(stdout,CASE_NORMAL,0,timestamp," AFS authentication \n") ; 489 #endif 490 #ifdef PRIVATE_AUTH 491 printmessage(stdout,CASE_NORMAL,0,timestamp," private authentication \n") ; 492 #else 493 printmessage(stdout,CASE_NORMAL,0,timestamp," default ssh command = %s \n",SSHCMD) ; 494 printmessage(stdout,CASE_NORMAL,0,timestamp," default ssh remote command = %s \n",SSHREMOTECMD) ; 495 #endif 496 #ifdef NDG_PYTHON_EMBED 497 printmessage(stdout,CASE_NORMAL,0,timestamp," Embedded in Python interpreter\n") ; 498 #endif // NDG_PYTHON_EMBED 499 500 printmessage(stdout,CASE_NORMAL,0,timestamp," default number of tries = %d \n",NBTRYMAX) ; 501 printmessage(stdout,CASE_NORMAL,0,timestamp," default sendwinsize = %d Kbytes\n",sendwinsize) ; 502 printmessage(stdout,CASE_NORMAL,0,timestamp," default recvwinsize = %d Kbytes\n",recvwinsize) ; 503 printmessage(stdout,CASE_NORMAL,0,timestamp," default number of stream = %d \n",nbport) ; 504 exit(0) ; 505 } 506 } 507 } 508 509 /** 510 * @todo replace getopt arguments with python calls. 511 */ 512 513 /* 514 ** Now all the others 515 */ 516 opterr = 0 ; 517 optind = 1 ; 518 while ((j = getopt(argc, argv, OPTIONS)) != -1) { 519 switch (j) { 520 case 'b' :{ 521 background = SETTOONE ; 522 break ; 523 } 524 case 'c' :{ 525 #ifdef WITH_GZIP 526 transferoption = transferoption | TROPT_GZIP ; 527 #else 528 printmessage(stderr,CASE_FATAL_ERROR,7,timestamp,"option -c is not available: bbftp was built without compression utility\n") ; 529 #endif 530 break ; 531 } 532 case 'd' :{ 533 debug = 1 ; 534 break ; 535 } 536 case 'D' :{ 537 if (optarg) { 538 if ((sscanf(optarg,"%d:%d",&i, &k) == 2) && (i < k)) { 539 pasvport_min = i; pasvport_max = k; 540 } else { 541 printmessage(stderr,CASE_FATAL_ERROR,4,timestamp,"Invalid port range : %s\n",optarg) ; 542 } 543 } else { 544 #ifdef PORT_RANGE 545 sscanf(PORT_RANGE,"%d:%d",&pasvport_min, &pasvport_max) ; 546 #endif 547 if (0 == pasvport_max) { 548 pasvport_min = 0; 549 pasvport_max = 1; 550 } 551 } 552 protocolmax = 2 ; 553 break ; 554 } 555 case 'e' : { 556 bbftpcmd = optarg ; 557 break ; 558 } 559 case 'E' : { 560 sshremotecmd = optarg ; 561 usessh = 1 ; 562 break ; 563 } 564 case 'f' :{ 565 errorfile = optarg ; 566 break ; 567 } 568 case 'i' :{ 569 inputfile = optarg ; 570 if ( stat (inputfile,&statbuf) < 0 ) { 571 printmessage(stderr,CASE_FATAL_ERROR,7,timestamp,"Input file (%s) cannot be stated\n",inputfile) ; 572 } 573 if ( (resultfile = (char *) malloc (strlen(inputfile) + 5 )) == NULL ) { 574 printmessage(stderr,CASE_FATAL_ERROR,1,timestamp,"Cannot malloc space for result file name\n") ; 575 } 576 strcpy(resultfile,inputfile) ; 577 strcat(resultfile,".res") ; 578 break ; 579 } 580 case 'I' :{ 581 sshidentityfile = optarg ; 582 usessh = 1 ; 583 /* 584 ** Check if file exists 585 */ 586 if ( stat (sshidentityfile,&statbuf) < 0 ) { 587 printmessage(stderr,CASE_FATAL_ERROR,5,timestamp,"SSH identity file (%s) cannot be stated\n",sshidentityfile) ; 588 } 589 break ; 590 } 591 case 'L' : { 592 sshcmd = optarg ; 593 usessh = 1 ; 594 break ; 595 } 596 case 'm' :{ 597 statoutput = SETTOONE ; 598 break ; 599 } 600 case 'n':{ 601 simulation_mode = SETTOONE ; 602 break ; 603 } 604 case 'o' :{ 605 outputfile = optarg ; 606 break ; 607 } 608 case 'P' :{ 609 privatestr = optarg ; 610 break ; 611 } 612 case 'q' :{ 613 transferoption = transferoption | TROPT_QBSS ; 614 break ; 615 } 616 case 'p' :{ 617 retcode = sscanf(optarg,"%d",&alluse) ; 618 if ( retcode != 1 || alluse < 0) { 619 printmessage(stderr,CASE_FATAL_ERROR,3,timestamp,"Number of streams must be numeric and > 0\n") ; 620 } 621 nbport = alluse ; 622 break ; 623 } 624 case 'r' :{ 625 retcode = sscanf(optarg,"%d",&alluse) ; 626 if ( retcode != 1 || alluse <= 0) { 627 printmessage(stderr,CASE_FATAL_ERROR,4,timestamp,"Number of tries must be numeric > 0\n") ; 628 } 629 globaltrymax = alluse ; 630 break ; 631 } 632 case 'R' :{ 633 bbftprcfile = optarg ; 634 break ; 635 } 636 case 's' :{ 637 usessh = SETTOONE ; 638 break ; 639 } 640 case 'S' :{ 641 usessh = SETTOONE ; 642 sshbatchmode = SETTOONE ; 643 break ; 644 } 645 case 't' :{ 646 timestamp = SETTOONE ; 647 break ; 648 } 649 case 'u' :{ 650 username = optarg ; 651 break ; 652 } 653 case 'V':{ 654 verbose = SETTOONE ; 655 break ; 656 } 657 case 'w' :{ 658 retcode = sscanf(optarg,"%d",&alluse) ; 659 if ( retcode != 1 || alluse <= 0) { 660 printmessage(stderr,CASE_FATAL_ERROR,4,timestamp,"Control port must be numeric\n") ; 661 } 662 newcontrolport = alluse ; 663 break ; 664 } 665 case 'W':{ 666 warning = SETTOONE ; 667 break ; 668 } 669 default : { 670 Usage() ; 671 printmessage(stderr,CASE_FATAL_ERROR,6,timestamp,"Error on command line (unsupported option -%c)\n",optopt) ; 672 } 673 } 674 } 675 287 if (0 == pasvport_max) { 288 pasvport_min = 0; 289 pasvport_max = 1; 290 } 291 } 292 protocolmax = 2 ; 293 break ; 294 295 case 'e' : 296 bbftpcmd = optarg ; 297 break ; 298 299 case 'm' : 300 statoutput = SETTOONE ; 301 break ; 302 303 case 'n': 304 simulation_mode = SETTOONE ; 305 break ; 306 307 case 'o' : 308 outputfile = optarg ; 309 break ; 310 311 case 'P' : 312 privatestr = optarg ; 313 break ; 314 315 case 'q' : 316 transferoption = transferoption | TROPT_QBSS ; 317 break ; 318 319 case 'p' : 320 retcode = sscanf(optarg,"%d",&alluse) ; 321 if ( retcode != 1 || alluse < 0) { 322 printmessage(stderr,CASE_FATAL_ERROR,3,timestamp,"Number of streams must be numeric and > 0\n") ; 323 } 324 nbport = alluse ; 325 break ; 326 327 case 'r' : 328 retcode = sscanf(optarg,"%d",&alluse) ; 329 if ( retcode != 1 || alluse <= 0) { 330 printmessage(stderr,CASE_FATAL_ERROR,4,timestamp,"Number of tries must be numeric > 0\n") ; 331 } 332 globaltrymax = alluse ; 333 break ; 334 335 case 'R' : 336 bbftprcfile = optarg ; 337 break ; 338 339 case 't' : 340 timestamp = SETTOONE ; 341 break ; 342 343 case 'u' : 344 username = optarg ; 345 break ; 346 347 case 'V': 348 verbose = SETTOONE ; 349 break ; 350 351 case 'w' : 352 retcode = sscanf(optarg,"%d",&alluse) ; 353 if ( retcode != 1 || alluse <= 0) { 354 printmessage(stderr,CASE_FATAL_ERROR,4,timestamp,"Control port must be numeric\n") ; 355 } 356 newcontrolport = alluse ; 357 break ; 358 359 case 'W': 360 warning = SETTOONE ; 361 break ; 362 363 default : 364 Usage() ; 365 printmessage(stderr,CASE_FATAL_ERROR,6,timestamp,"Error on command line (unsupported option -%c)\n",optopt) ; 366 367 } 368 } 369 370 /* 371 ** Reset all outputs variable if statoutput is set to one 372 */ 373 if ( statoutput ) { 374 debug = SETTOZERO ; 375 verbose = SETTOZERO ; 376 warning = SETTOZERO ; 377 timestamp = SETTOZERO ; 378 } 379 380 381 382 /** 383 * @todo replace hostname code with something better. 384 */ 385 386 /* 387 ** Check hostname 388 */ 389 if ( optind == argc-1 ) { 390 hostname= argv[optind] ; 391 } 392 else { 393 printmessage(stderr,CASE_FATAL_ERROR,24,timestamp,"Unable to find hostname\n"); 394 } 395 if (hostname == NULL || strlen(hostname) == 0) { 396 Usage() ; 397 printmessage(stderr,CASE_FATAL_ERROR,14,timestamp,"No hostname on command line\n") ; 398 } 399 /* 400 ** Check if hostname is in numeric format 401 */ 402 for (j=0 ; j < strlen(hostname) ; j++) { 403 if ( isalpha(hostname[j]) ) { 404 /* 405 ** One alpha caractere means no numeric form 406 */ 407 hosttype = 1 ; 408 break ; 409 } else if ( isdigit(hostname[j]) ) { 410 } else if ( hostname[j] == '.' ) { 411 } else { 412 printmessage(stderr,CASE_FATAL_ERROR,15,timestamp,"Invalid hostname (%s)\n",hostname) ; 413 } 414 } 415 if ( hosttype == 0 ) { 676 416 /* 677 ** Reset all outputs variable if statoutput is set to one417 ** Numeric format 678 418 */ 679 if ( statoutput ) { 680 debug = SETTOZERO ; 681 verbose = SETTOZERO ; 682 warning = SETTOZERO ; 683 timestamp = SETTOZERO ; 684 } 685 686 /* 687 ** Check all ssh stuff 688 */ 689 if ( usessh) { 690 if ( sshremotecmd == NULL ) { 691 /* 692 ** Malloc space and set the default 693 */ 694 if ( (sshremotecmd = (char *) malloc (strlen(SSHREMOTECMD)+1) ) == NULL ) { 695 printmessage(stderr,CASE_FATAL_ERROR,8,timestamp,"Cannot malloc space for ssh remote cmd\n") ; 696 } 697 strcpy(sshremotecmd,SSHREMOTECMD) ; 698 } else { 699 /* 700 ** Verify if -s is present if not add it (in order to fit v 1.9.4-tja1 701 ** behaviour) 702 */ 703 if ( strstr(sshremotecmd," -s") == NULL ) { 704 if ( ( tmpsshremotecmd = (char *) malloc (strlen(sshremotecmd) + 4) ) == NULL ) { 705 printmessage(stderr,CASE_FATAL_ERROR,8,timestamp,"Cannot malloc space for ssh remote cmd\n") ; 706 } 707 sprintf(tmpsshremotecmd,"%s -s",sshremotecmd) ; 708 sshremotecmd = tmpsshremotecmd ; 709 } 710 } 711 if ( sshcmd == NULL ) { 712 if ( (sshcmd = (char *) malloc (strlen(SSHCMD)+1) ) == NULL ) { 713 printmessage(stderr,CASE_FATAL_ERROR,9,timestamp,"Cannot malloc space for ssh cmd\n") ; 714 } 715 strcpy(sshcmd,SSHCMD) ; 716 } 717 } 718 719 720 /** 721 * @todo replace hostname code with something better. 722 */ 723 724 /* 725 ** Check hostname 726 */ 727 if ( optind == argc-1 ) { 728 hostname= argv[optind] ; 419 hisctladdr.sin_addr.s_addr = 0 ; 420 hisctladdr.sin_addr.s_addr = inet_addr(hostname) ; 421 if (hisctladdr.sin_addr.s_addr == -1 ) { 422 printmessage(stderr,CASE_FATAL_ERROR,16,timestamp,"Invalid IP address (%s)\n",hostname) ; 423 } 424 calchostname = (char *)inet_ntoa(hisctladdr.sin_addr) ; 425 if ( strcmp(hostname,calchostname) ) { 426 printmessage(stderr,CASE_FATAL_ERROR,16,timestamp,"Invalid IP address (%s)\n",hostname) ; 427 } 428 } else { 429 /* 430 ** Alpha format 431 */ 432 if ( (hp = gethostbyname((char *)hostname) ) == NULL ) { 433 printmessage(stderr,CASE_FATAL_ERROR,17,timestamp,"Hostname no found (%s)\n",hostname) ; 729 434 } else { 730 printmessage(stderr,CASE_FATAL_ERROR,24,timestamp,"Unable to find hostname\n"); 731 732 if (hostname == NULL || strlen(hostname) == 0) { 733 Usage() ; 734 printmessage(stderr,CASE_FATAL_ERROR,14,timestamp,"No hostname on command line\n") ; 735 } 736 /* 737 ** Check if hostname is in numeric format 738 */ 739 for (j=0 ; j < strlen(hostname) ; j++) { 740 if ( isalpha(hostname[j]) ) { 741 /* 742 ** One alpha caractere means no numeric form 743 */ 744 hosttype = 1 ; 745 break ; 746 } else if ( isdigit(hostname[j]) ) { 747 } else if ( hostname[j] == '.' ) { 748 } else { 749 printmessage(stderr,CASE_FATAL_ERROR,15,timestamp,"Invalid hostname (%s)\n",hostname) ; 750 } 751 } 752 if ( hosttype == 0 ) { 753 /* 754 ** Numeric format 755 */ 756 hisctladdr.sin_addr.s_addr = 0 ; 757 hisctladdr.sin_addr.s_addr = inet_addr(hostname) ; 758 if (hisctladdr.sin_addr.s_addr == -1 ) { 759 printmessage(stderr,CASE_FATAL_ERROR,16,timestamp,"Invalid IP address (%s)\n",hostname) ; 760 } 761 calchostname = (char *)inet_ntoa(hisctladdr.sin_addr) ; 762 if ( strcmp(hostname,calchostname) ) { 763 printmessage(stderr,CASE_FATAL_ERROR,16,timestamp,"Invalid IP address (%s)\n",hostname) ; 764 } 765 } else { 766 /* 767 ** Alpha format 768 */ 769 if ( (hp = gethostbyname((char *)hostname) ) == NULL ) { 770 printmessage(stderr,CASE_FATAL_ERROR,17,timestamp,"Hostname no found (%s)\n",hostname) ; 771 } else { 772 if (hp->h_length > (int)sizeof(hisctladdr.sin_addr)) { 773 hp->h_length = sizeof(hisctladdr.sin_addr); 774 } 775 memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0], hp->h_length) ; 776 } 777 } 778 /* 779 ** Check username if not in certificate authentication mode 780 */ 781 if ( username == NULL ) { 782 if (!usessh) { 783 Usage() ; 784 printmessage(stderr,CASE_FATAL_ERROR,18,timestamp,"No username given\n") ; 785 } 786 } 787 if ( debug ) { 788 if (simulation_mode) { 789 printmessage(stdout,CASE_NORMAL,0,timestamp,"** SIMULATION MODE: No data written **\n") ; 790 } 791 printmessage(stdout,CASE_NORMAL,0,timestamp,"Starting parameters -----------------\n") ; 792 printmessage(stdout,CASE_NORMAL,0,timestamp,"number of tries = %d\n",globaltrymax) ; 793 printmessage(stdout,CASE_NORMAL,0,timestamp,"number of streams = %d\n",nbport) ; 794 printmessage(stdout,CASE_NORMAL,0,timestamp,"localumask = %03o\n",localumask) ; 795 printmessage(stdout,CASE_NORMAL,0,timestamp,"remoteumask = %03o\n",remoteumask) ; 796 printmessage(stdout,CASE_NORMAL,0,timestamp,"remotecos = %d\n",remotecos) ; 797 printmessage(stdout,CASE_NORMAL,0,timestamp,"buffersize = %d KB\n",buffersizeperstream) ; 798 printmessage(stdout,CASE_NORMAL,0,timestamp,"sendwinsize = %d KB\n",sendwinsize) ; 799 printmessage(stdout,CASE_NORMAL,0,timestamp,"recvwinsize = %d KB\n",recvwinsize) ; 800 printmessage(stdout,CASE_NORMAL,0,timestamp,"ackto = %d s\n",ackto) ; 801 printmessage(stdout,CASE_NORMAL,0,timestamp,"recvcontrolto = %d s\n",recvcontrolto) ; 802 printmessage(stdout,CASE_NORMAL,0,timestamp,"sendcontrolto = %d s\n",sendcontrolto) ; 803 printmessage(stdout,CASE_NORMAL,0,timestamp,"datato = %d s\n",datato) ; 804 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_DIR ) == TROPT_DIR) ? "createdir" : "nocreatedir") ; 805 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_TMP ) == TROPT_TMP) ? "tmpfile" : "notmpfile") ; 806 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_RFIO ) == TROPT_RFIO) ? "remoterfio" : "noremoterfio") ; 807 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_MODE ) == TROPT_MODE) ? "keepmode" : "nokeepmode") ; 808 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_ACC ) == TROPT_ACC) ? "keepaccess" : "nokeepaccess") ; 809 #ifdef WITH_GZIP 810 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_GZIP ) == TROPT_GZIP) ? "gzip" : "nogzip") ; 811 #endif 812 printmessage(stdout,CASE_NORMAL,0,timestamp,"option %s\n", ((transferoption & TROPT_QBSS ) == TROPT_QBSS) ? "qbss" : "noqbss") ; 813 printmessage(stdout,CASE_NORMAL,0,timestamp,"-------------------------------------\n") ; 814 printmessage(stdout,CASE_NORMAL,0,timestamp,"Connection mode ---------------------\n") ; 815 if ( usecert ) { 816 /* if ( username == NULL ) {*/ 817 printmessage(stdout,CASE_NORMAL,0,timestamp,"Using certificate authentication\n") ; 818 /* } else { 819 printmessage(stdout,CASE_NORMAL,0,timestamp,"Using standard bbftp mode\n") ; 820 }*/ 821 } else if ( useprivate ) { 822 printmessage(stdout,CASE_NORMAL,0,timestamp,"Using private authentication\n") ; 823 } else if ( usessh) { 824 printmessage(stdout,CASE_NORMAL,0,timestamp,"Using ssh mode\n") ; 825 printmessage(stdout,CASE_NORMAL,0,timestamp," ssh command = %s \n",sshcmd) ; 826 printmessage(stdout,CASE_NORMAL,0,timestamp," ssh remote command = %s \n",sshremotecmd) ; 827 } else { 828 printmessage(stdout,CASE_NORMAL,0,timestamp,"Using standard bbftp mode\n",localumask) ; 829 } 830 printmessage(stdout,CASE_NORMAL,0,timestamp,"-------------------------------------\n") ; 831 } 832 833 /* 834 ** Ask for password if not in ssh mode 835 */ 836 #ifdef PRIVATE_AUTH 837 if ( bbftp_private_getargs(logmessage) < 0 ) { 838 printmessage(stderr,CASE_FATAL_ERROR,19,timestamp,"Error while private authentication : %s\n",logmessage) ; 839 } 840 #else 841 if ((!usessh && !usecert)/* || (usecert && username)*/) { 842 # ifdef AFS 843 char *reasonString, passwordBuffer[1024] ; 844 long code ; 845 if ( (code = ka_UserReadPassword("Password: ", passwordBuffer, sizeof(passwordBuffer), &reasonString)) ) { 846 printmessage(stderr,CASE_FATAL_ERROR,19,timestamp,"Error while entering password\n") ; 847 } 848 if ( ( password = (char *) malloc (strlen(passwordBuffer) + 1) ) == NULL ) { 849 printmessage(stderr,CASE_FATAL_ERROR,54,timestamp,"Unable to store password : malloc failed (%s)\n",strerror(errno)) ; 850 return -1 ; 851 } 852 strcpy(password, passwordBuffer); 853 # else 854 # ifdef USE_GETPASSPHRASE 855 password = (char *) getpassphrase("Password: ") ; 856 if ( strlen(password) == 0 ) { 857 printmessage(stderr,CASE_FATAL_ERROR,19,timestamp,"Password is mandatory\n") ; 858 } 859 # else 860 printmessage(stdout,CASE_NORMAL,0,0,"Password: ") ; 861 password = (char *) getpass("") ; 862 # endif /* USE_GETPASSPHRASE */ 863 # endif /* AFS */ 864 } 865 #endif 866 867 /* 868 ** Set the signals 869 */ 870 bbftp_setsignals() ; 871 872 873 if ( debug ) 874 printmessage(stdout,CASE_NORMAL,0,timestamp,"Connecting to server ----------------\n",localumask) ; 875 reconnecttoserver() ; 876 if ( debug ) 877 printmessage(stdout,CASE_NORMAL,0,timestamp,"Connecting end ---------------------\n",localumask) ; 878 879 /* 880 ** Start the infinite loop 881 */ 882 { 883 cmd_list *iterator; 884 iterator = commandList; 885 while (iterator != NULL) { 886 if ( treatcommand(iterator->cmd) == 0 ) { 887 if ( inputfile != NULL ) { 888 write(resfd,iterator->cmd,strlen(iterator->cmd)) ; 889 write(resfd," OK\n",4) ; 890 } else { 891 if (!verbose && !statoutput) printmessage(stdout,CASE_NORMAL,0,timestamp,"%s OK\n",iterator->cmd); 892 } 893 } else { 894 if ( inputfile != NULL ) { 895 write(resfd,iterator->cmd,strlen(iterator->cmd)) ; 896 write(resfd," FAILED\n",8) ; 897 } else { 898 if (!verbose && !statoutput) printmessage(stdout,CASE_NORMAL,0,timestamp,"%s FAILED\n",iterator->cmd); 899 } 900 } 901 iterator = iterator->next; 435 if (hp->h_length > (int)sizeof(hisctladdr.sin_addr)) { 436 hp->h_length = sizeof(hisctladdr.sin_addr); 902 437 } 903 } 904 if ( inputfile != NULL ) { 905 close(infd) ; 906 close(resfd) ; 907 } 908 msg = (struct message *)minbuffer ; 909 msg->code = MSG_CLOSE_CONN ; 910 msg->msglen = 0 ; 911 /* 912 ** We do not care of the result because this routine is called 913 ** only at the end of the client 914 */ 915 writemessage(outcontrolsock,minbuffer,MINMESSLEN,sendcontrolto,0) ; 916 sleep(1) ; 917 bbftp_close_control() ; 918 #ifndef NDG_PYTHON_EMBED 919 exit(myexitcode) ; 920 #endif 438 memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0], hp->h_length) ; 439 } 440 } 441 /* 442 ** Check username if not in certificate authentication mode 443 */ 444 if ( username == NULL ) { 445 Usage() ; 446 printmessage(stderr,CASE_FATAL_ERROR,18,timestamp,"No username given\n") ; 447 } 448 if ( debug ) { 449 print_debug(); 450 } 451 452 if ( bbftp_private_getargs(logmessage) < 0 ) { 453 printmessage(stderr,CASE_FATAL_ERROR,19,timestamp,"Error while private authentication : %s\n",logmessage) ; 454 } 455 456 /* 457 ** Set the signals 458 */ 459 bbftp_setsignals() ; 460 461 462 if ( debug ) 463 printmessage(stdout,CASE_NORMAL,0,timestamp,"Connecting to server ----------------\n",localumask) ; 464 reconnecttoserver() ; 465 if ( debug ) 466 printmessage(stdout,CASE_NORMAL,0,timestamp,"Connecting end ---------------------\n",localumask) ; 467 468 if ( treatcommand(bbftpcmd) == 0 ) { 469 if (!verbose && !statoutput) printmessage(stdout,CASE_NORMAL,0,timestamp,"%s OK\n",bbftpcmd); 470 } else { 471 if (!verbose && !statoutput) printmessage(stdout,CASE_NORMAL,0,timestamp,"%s FAILED\n",bbftpcmd); 472 } 473 474 close_connection(); 921 475 } 476
Note: See TracChangeset
for help on using the changeset viewer.