Main Page | Data Structures | File List | Data Fields | Globals

lcg-scr.c

Go to the documentation of this file.
00001 
00008 /* lcg-scr.c - Secure copy User Interface to Grid
00009  * ====================================================================
00010  * Copyright (c) Giordano Scuderi, Unico SRL.  All rights reserved.
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions
00014  * are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  *    notice, this list of conditions and the following disclaimer. 
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright
00020  *    notice, this list of conditions and the following disclaimer in
00021  *    the documentation and/or other materials provided with the
00022  *    distribution.
00023  *
00024  * 3. All advertising materials mentioning features or use of this
00025  *    software must display the following acknowledgment:
00026  *    "This product includes software developed by Giordano Scuderi
00027  *    for Unico SRL"
00028  *
00029  * 4. The names "Secure Storage" must not be used to
00030  *    endorse or promote products derived from this software without
00031  *    prior written permission. For written permission, please contact
00032  *    gscuderi@unicosrl.it.
00033  *
00034  * 5. Products derived from this software may not be called "Secure Storage"
00035  *    nor may "Secure Storage" appear in their names without prior written
00036  *    permission of Giordano Scuderi (Unico SRL).
00037  *
00038  * 6. Redistributions of any form whatsoever must retain the following
00039  *    acknowledgment:
00040  *    "This product includes software developed by Giordano Scuderi
00041  *    for Unico SRL"
00042  *
00043  * THIS SOFTWARE IS PROVIDED BY UNICO SRL ``AS IS'' AND ANY
00044  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00045  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00046  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNICO SRL OR
00047  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00048  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00049  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00050  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00051  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00052  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00053  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00054  * OF THE POSSIBILITY OF SUCH DAMAGE.
00055  * ====================================================================
00056  *
00057  * "This product includes software developed by the OpenSSL Project
00058  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
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 } /* closing brace for extern "C" */
00087 #endif           
00088 
00089 /* Flag set by --verbose and --insecure */
00090 static int insecure, verbose;
00091         
00092 /* Print help screen and exit */
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 /* MAIN */
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         // Valid character
00118         const char *accept_host=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.-";
00119         const char *accept_vo=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789-";
00120         const char *accept_lfn=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.:_/-";
00121         
00122         // Input parameter parsing
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         // If -L not specified the program print help screen and exit
00169         if (lfn_dest==NULL) {
00170                 usage(stderr);  
00171         }
00172         // Verify length of destination lfn
00173         if (strlen(lfn_dest) + 1 > LCG_MAXPATHLEN) {
00174                 fprintf (stderr, "Invalid lfn : %s \n", lfn_dest);
00175                 exit(1);
00176         }
00177         // Verify if --vo flag was specified or exist Environment variable LCG_GFAL_VO
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                 // Get default SE from Environment Variable
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         // Input parameters filter
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         // Verify source file length
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         //Call lcg_scr from secure storage Library
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 }

Generated on Wed May 30 09:56:30 2007 for Secure Storage Service by doxygen 1.3.5