00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #ifdef __cplusplus
00063 extern "C" {
00064 #endif
00065
00066 #include <sys/types.h>
00067 #include <sys/stat.h>
00068 #include <errno.h>
00069 #include <stdio.h>
00070 #include <string.h>
00071 #include <getopt.h>
00072 #include <stdlib.h>
00073 #include <fcntl.h>
00074 #if defined(_WIN32)
00075 #include <io.h>
00076 #else
00077 #include <unistd.h>
00078 #endif
00079 #include <sys/mman.h>
00080 #include <dlfcn.h>
00081 #include "lcg-scp.h"
00082 #include "securestorage.h"
00083
00084 #ifdef __cplusplus
00085 }
00086 #endif
00087
00088
00089 int insecure, verbose;
00090
00091 extern int errno;
00092
00093
00094 void usage(FILE *out) {
00095 fprintf ( out, "%s Version %s\n", PROGRAMNAME, PROGRAMVERSION);
00096 fprintf ( out, "By %s for %s.\n",AUTHOR, COMPANY);
00097 fprintf ( out, "\nUsage: %s [--vo vo] [-v | --verbose] [-h | --help] [-i | --insecure]\n", PROGRAMNAME);
00098 fprintf ( out, "\t[--config config_file] <src_lfn> <dest_file>\n");
00099 if (out == stdout)
00100 exit(0);
00101 else
00102 exit(1);
00103 }
00104
00105
00106 int main (int argc, char *argv[]) {
00107
00108
00109 char *vo= NULL;
00110 char *sourcefile=NULL;
00111 char destfile[MAXPATHLENGTH];
00112 int flag;
00113 size_t inv;
00114 char *conf_file = NULL;
00115 insecure=0;
00116 verbose=0;
00117
00118 const char *accept_vo=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789-";
00119 const char *accept_lfn=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.:_/-";
00120
00121
00122 static struct option longopts[] ={
00123 { "vo", required_argument, 0, 'V' },
00124 { "verbose", no_argument, &verbose, 1 },
00125 { "help", no_argument, 0, 'H' },
00126 { "config", required_argument, 0, 'C' },
00127 { "insecure", no_argument, &insecure, 1 },
00128 {0, 0, 0, 0}
00129 };
00130 while ((flag = getopt_long (argc, argv, "hvi", longopts, NULL)) != EOF) {
00131 switch (flag) {
00132 case 'h':
00133 usage(stdout);
00134 break;
00135 case 'H':
00136 usage(stdout);
00137 break;
00138 case 'V':
00139 vo=optarg;
00140 break;
00141 case 'v':
00142 verbose=1;
00143 break;
00144 case 'i':
00145 insecure = 1;
00146 break;
00147 case 'C':
00148 conf_file=optarg;
00149 break;
00150 default:
00151 break;
00152 }
00153 }
00154
00155 if (optind+1 >= argc) {
00156 usage(stderr);
00157 }
00158
00159 if (vo == NULL){
00160 vo = getenv(VO);
00161 if (!vo) {
00162 fprintf(stderr, "VO not specified and environment variable LCG_GFAL_VO not set.\n");
00163 exit(1);
00164 }
00165 }
00166
00167 if (strlen(argv[optind]) > MAXPATHLENGTH) {
00168 fprintf(stderr, "The source file path is too long!\n");
00169 exit(1);
00170 }
00171 sourcefile=argv[optind];
00172 strcpy(destfile,argv[optind+1]);
00173
00174 if (sourcefile==NULL) {
00175 fprintf(stderr, "You must specify source lfn!\n");
00176 exit(1);
00177 }
00178 if(destfile==NULL) {
00179 fprintf(stderr, "You must specify destination file!\n");
00180 exit(1);
00181 }
00182
00183 if (strlen (sourcefile) + 1 > LCG_MAXPATHLEN) {
00184 fprintf (stderr, "Invalid lfn : %s \n", sourcefile);
00185 exit(1);
00186 }
00187
00188 inv=0;
00189 inv = strspn(vo, accept_vo);
00190 if (inv != strlen(vo) ) {
00191 fprintf(stderr,"Invalid character on VO parameter.\n");
00192 exit(1);
00193 }
00194 inv=0;
00195 inv = strspn(sourcefile, accept_lfn);
00196 if (inv != strlen(sourcefile) ) {
00197 fprintf(stderr,"Invalid character on Source File parameter.\n");
00198 exit(1);
00199 }
00200
00201
00202 if ( lcg_scp(sourcefile,destfile,vo,conf_file,insecure,verbose) < 0 ) {
00203 int errno_save = errno;
00204 fprintf(stderr, "%s\n", securestorage_error(errno_save));
00205 exit(1);
00206 }
00207
00208 exit(0);
00209 }
00210