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 #include <ctype.h>
00075 #if defined(_WIN32)
00076 #include <io.h>
00077 #else
00078 #include <unistd.h>
00079 #endif
00080 #include <sys/mman.h>
00081 #include <dlfcn.h>
00082 #include "lcg-scr.h"
00083 #include "securestorage.h"
00084
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088
00089
00090 static int insecure, verbose;
00091
00092
00093 void usage(FILE *out) {
00094 fprintf ( out, "%s Version %s\n", PROGRAMNAME, PROGRAMVERSION);
00095 fprintf ( out, "By %s for %s.\n",AUTHOR, COMPANY);
00096 fprintf ( out, "\nUsage: %s [--vo vo] [-d SE] [-g guid] [-v | --verbose] \n", PROGRAMNAME);
00097 fprintf ( out, "\t[-h | --help] [-i | --insecure] [--config config_file] \n");
00098 fprintf ( out, "\t<-l dest_lfn> <src_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 int flag, result;
00109 char localfilename[MAXPATHLENGTH];
00110 size_t inv;
00111 char *lfn_dest=NULL, *dest_se=NULL, *vo=NULL;
00112 char actual_gid[37];
00113 insecure=0;
00114 verbose=0;
00115 char *conf_file = NULL;
00116 char *guid=NULL;
00117
00118 const char *accept_host=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.-";
00119 const char *accept_vo=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789-";
00120 const char *accept_lfn=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.:_/-";
00121
00122
00123 static struct option longopts[] ={
00124 { "vo", required_argument, 0, 'V' },
00125 { "verbose", no_argument, &verbose, 1 },
00126 { "help", no_argument, 0, 'H' },
00127 { "config", required_argument, 0, 'C' },
00128 { "insecure", no_argument, &insecure, 1 },
00129 {0, 0, 0, 0}
00130 };
00131 while ((flag = getopt_long (argc, argv, "d:l:hvig:", longopts, NULL)) != EOF) {
00132 switch (flag) {
00133 case 'd':
00134 dest_se=optarg;
00135 break;
00136 case 'l':
00137 lfn_dest=optarg;
00138 break;
00139 case 'h':
00140 usage(stdout);
00141 break;
00142 case 'H':
00143 usage(stdout);
00144 break;
00145 case 'V':
00146 vo=optarg;
00147 break;
00148 case 'v':
00149 verbose=1;
00150 break;
00151 case 'i':
00152 insecure = 1;
00153 break;
00154 case 'g':
00155 guid=optarg;
00156 break;
00157 case 'C':
00158 conf_file=optarg;
00159 break;
00160 default:
00161 break;
00162 }
00163 }
00164
00165 if (optind >= argc) {
00166 usage(stderr);
00167 }
00168
00169 if (lfn_dest==NULL) {
00170 usage(stderr);
00171 }
00172
00173 if (strlen(lfn_dest) + 1 > LCG_MAXPATHLEN) {
00174 fprintf (stderr, "Invalid lfn : %s \n", lfn_dest);
00175 exit(1);
00176 }
00177
00178 if (vo == NULL){
00179 vo = getenv(VO);
00180 if (!vo) {
00181 fprintf(stderr, "VO not specified and environment variable LCG_GFAL_VO not set.\n");
00182 exit(1);
00183 }
00184 }
00185 if (dest_se == NULL){
00186
00187 char *storageelementdest;
00188 int i;
00189 char oo[strlen(vo)+1];
00190 strcpy(oo,vo);
00191 for (i=0; oo[i]!=0; i++)
00192 oo[i] = toupper(oo[i]);
00193 storageelementdest = calloc(1, (strlen(oo)+strlen("VO_%s_DEFAULT_SE")+1));
00194 sprintf(storageelementdest,"VO_%s_DEFAULT_SE",oo);
00195 dest_se = getenv(storageelementdest);
00196 if (!dest_se) {
00197 fprintf(stderr, "Destination SE not specified and environment variable %s not set.\n", storageelementdest);
00198 free(storageelementdest);
00199 exit(1);
00200 }
00201 free(storageelementdest);
00202 }
00203
00204 if (guid!=NULL) {
00205 if (strlen(guid)!=36 ) {
00206 fprintf(stderr, "Invalid GUID: %s\n", guid);
00207 exit(1);
00208 }
00209 }
00210
00211 inv=0;
00212 inv = strspn(dest_se, accept_host);
00213 if (inv != strlen(dest_se) ) {
00214 fprintf(stderr,"Invalid character on Destination SE parameter.\n");
00215 exit(1);
00216 }
00217 inv=0;
00218 inv = strspn(vo, accept_vo);
00219 if (inv != strlen(vo) ) {
00220 fprintf(stderr,"Invalid character on VO parameter.\n");
00221 exit(1);
00222 }
00223 inv=0;
00224 inv = strspn(lfn_dest, accept_lfn);
00225 if (inv != strlen(lfn_dest) ) {
00226 fprintf(stderr,"Invalid character on Destination LFN parameter.\n");
00227 exit(1);
00228 }
00229
00230
00231 if (strlen(argv[optind]) > MAXPATHLENGTH) {
00232 fprintf(stderr, "The source file path is too long!\n");
00233 exit(1);
00234 }
00235 strcpy(localfilename,argv[optind]);
00236
00237
00238 if ( (result = lcg_scr(localfilename,dest_se,guid,lfn_dest,vo, \
00239 conf_file,insecure,verbose,actual_gid)) < 0 ) {
00240
00241 int errno_save = errno;
00242 fprintf(stderr, "%s\n", securestorage_error(errno_save));
00243 exit(1);
00244 }
00245
00246 exit(0);
00247 }