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

lcg-sdel.c

Go to the documentation of this file.
00001 
00008 /* lcg-sdel.c - Delete data and KEY from 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 <ctype.h>
00074 #include <fcntl.h>
00075 #if defined(_WIN32)
00076 #include <io.h>
00077 #else
00078 #include <unistd.h>
00079 #endif
00080 #include <dlfcn.h>
00081 #include "lcg-sdel.h"
00082 #include "securestorage.h"
00083 
00084 #ifdef __cplusplus
00085 } /* closing brace for extern "C" */
00086 #endif
00087 
00088 
00089 /* Flag set by --verbose and --insecure */
00090 int insecure, verbose;
00091 
00092 int helpflg;
00093 // Valid character
00094 const char *accept_host=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.-";
00095 const char *accept_vo=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789-";
00096 const char *accept_lfn=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.:_/-";
00097 
00098 /* Print help screen and exit */
00099 void usage(FILE *out) {
00100         fprintf ( out, "%s Version %s\n", PROGRAMNAME, PROGRAMVERSION);
00101         fprintf ( out, "By %s for %s.\n",AUTHOR, COMPANY);
00102         fprintf ( out, "\nUsage: %s [--vo VO] [-a | -s SE] [-v | --verbose] [-h | --help] [-t timeout]\n", PROGRAMNAME);
00103         fprintf ( out, "\t[-i | --insecure] [--config config_file] <lfn_to_delete>\n");
00104         fprintf ( out, " -s SE : Delete replica in specified SE\n");
00105         fprintf ( out, " -a    : Delete all replica's\n");
00106         if (out == stdout)
00107                 exit(0);
00108         else
00109                 exit(-1);       
00110 }       
00111 
00112 int main(int argc, char *argv[]) {
00113         int aflag = 0;
00114         int c;
00115         char *conf_file = NULL;
00116         int errflg = 0;
00117         static struct option longopts[] = {
00118                 {"config", required_argument, 0, 'C'},
00119                 {"help", no_argument, &helpflg, 1},
00120                 {"insecure", no_argument, &insecure, 1},
00121                 {"verbose", no_argument, &verbose, 1},
00122                 {"vo", required_argument, 0, 'V'},
00123                 {0, 0, 0, 0}
00124         };
00125         char *se = NULL;
00126         char *vo = NULL;
00127         char *src_file = NULL;
00128         char *dp;
00129         int timeout = 0;
00130         insecure=0;
00131         size_t inv;
00132         
00133         opterr = 0;
00134         while ((c = getopt_long (argc, argv, "ahis:vt:", longopts, NULL)) != EOF) {
00135                 switch (c) {
00136                 case 'a':
00137                         aflag = 1;
00138                         break;
00139                 case 'C':
00140                         conf_file = optarg;
00141                         break;
00142                 case 'h':
00143                         helpflg = 1;
00144                         break;
00145                 case 'i':
00146                         insecure = 1;
00147                         break;
00148                 case 's':
00149                         se = optarg;
00150                         break;
00151                 case 'V':
00152                         vo = optarg;
00153                         break;
00154                 case 'v':
00155                         verbose = 1;
00156                         break;
00157                 case 't':
00158                         if ((timeout = strtol (optarg, &dp, 10)) < 1 ||
00159                            *dp != '\0') {
00160                                 fprintf (stderr, 
00161                                 "invalid value of timeout %s\n", optarg);
00162                                 errflg++;
00163                         }
00164                         break;
00165                 case '?':
00166                         errflg++;
00167                         break;
00168                 default:
00169                         break;
00170                 }
00171         }
00172         if (optind >= argc) {
00173                 errflg++;
00174         }
00175         if (errflg || helpflg) {
00176                 if(helpflg)
00177                         usage(stdout);
00178                 else
00179                         usage(stderr);
00180         }
00181 
00182         src_file = argv[optind];
00183         if (src_file==NULL) {
00184                 fprintf(stderr, "You must specify source lfn!\n");
00185                 exit(1);
00186         }
00187         // Verify length of destination lfn
00188         if (strlen (src_file) + 1 > LCG_MAXPATHLEN) {
00189                 fprintf (stderr, "Invalid lfn : %s \n", src_file);
00190                 exit(1);
00191         }
00192         if (vo == NULL) {
00193                 vo = getenv("LCG_GFAL_VO");
00194                 if (!vo) {
00195                         fprintf(stderr, "VO not specified and LCG_GFAL_VO not set.\n");
00196                         exit(1);
00197                 }
00198         }
00199         // Input file must be an LFN
00200         if (strncmp (src_file, "lfn:", 4) != 0) {
00201                 fprintf (stderr, "Invalid lfn : %s \n", argv[optind]);
00202                 exit(1);        
00203         }
00204         
00205         // Get default SE from Environment Variable
00206         char oo[strlen(vo)+1];
00207         char *storageelementdest;
00208         int i;
00209         strcpy(oo,vo);
00210         for (i=0; oo[i]!=0; i++)
00211                 oo[i] = toupper(oo[i]);
00212         storageelementdest = calloc(1, (strlen(oo)+strlen("VO_%s_DEFAULT_SE")+1));
00213         sprintf(storageelementdest,"VO_%s_DEFAULT_SE",oo);
00214         se = getenv(storageelementdest);
00215         if ( aflag == 0 && se == NULL) {
00216                 fprintf (stderr, "Flag -s or -a not specified and %s not set.\n", storageelementdest);
00217                 free(storageelementdest);
00218                 exit(1);        
00219         }
00220         free(storageelementdest);
00221         // Input parameters filter
00222         inv=0;
00223         inv = strspn(vo, accept_vo);
00224         if (inv != strlen(vo) ) {
00225                 fprintf(stderr,"Invalid character on VO parameter.\n");
00226                 exit(1);
00227         }
00228         inv=0;
00229         inv = strspn(src_file, accept_lfn);
00230         if (inv != strlen(src_file) ) {
00231                 fprintf(stderr,"Invalid character on Source File parameter.\n");
00232                 exit(1);
00233         }
00234         if (se != NULL) {
00235                 inv=0;
00236                 inv = strspn(se, accept_host);
00237                 if (inv != strlen(se) ) {
00238                         fprintf(stderr,"Invalid character on SE parameter.\n");
00239                         exit(1);
00240                 }
00241         }       
00242         
00243         //Call lcg_sdel from secure storage Library
00244         if ( lcg_sdel(src_file,aflag,se,vo,conf_file,insecure,verbose,timeout) < 0) {
00245                 int errno_save = errno;
00246                 fprintf(stderr, "%s\n", securestorage_error(errno_save));
00247                 exit(1);
00248         }
00249         exit (0);
00250 }

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