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

lcg-scp.c

Go to the documentation of this file.
00001 
00008 /* lcg-scp.c - Secure copy from Grid to User Interface
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 #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 } /* closing brace for extern "C" */
00086 #endif
00087 
00088 /* Flag set by --verbose and --insecure */
00089 int insecure, verbose;
00090 
00091 extern int errno;
00092 
00093 /* Print help screen and exit */
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 /* MAIN */
00106 int main (int argc, char *argv[]) {
00107         
00108         // Variable definition
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         // Valid character
00118         const char *accept_vo=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789-";
00119         const char *accept_lfn=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.:_/-";
00120         
00121         // Input parameter parsing
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         // Verify if --vo flag was specified or exist Environment variable LCG_GFAL_VO
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         // Verify length of destination lfn
00183         if (strlen (sourcefile) + 1 > LCG_MAXPATHLEN) {
00184                 fprintf (stderr, "Invalid lfn : %s \n", sourcefile);
00185                 exit(1);
00186         }
00187         // Input parameters filter
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         //Call lcg_scp from secure storage Library
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 

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