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 <fcntl.h>
00074 #if defined(_WIN32)
00075 #include <io.h>
00076 #else
00077 #include <unistd.h>
00078 #endif
00079 #include <dlfcn.h>
00080 #include <ctype.h>
00081 #include <gfal_api.h>
00082 #include "lcg_util.h"
00083 #include "ss-util.h"
00084 #include "lcg_sdel.h"
00085 #include "keystore_client.h"
00086 
00087 #ifdef __cplusplus
00088 } /* closing brace for extern "C" */
00089 #endif
00090 
00091 //extern const char *const ss_errlist[];
00092 //extern int  securestorage_nerr;
00093 
00094 /*
00095  * LCG_SDEL Function 
00096  *
00097  */
00098 int lcg_sdel(char *src_file,int aflag,char *se,char *vo,char *conf_file,
00099                                 int insecure,int verbose,int timeout) {
00100         
00101         int deletekey=0;
00102         size_t inv;
00103         char *src_file_new;
00104         // Valid character
00105         const char *accept_host=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.-";
00106         const char *accept_vo=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789-";
00107         const char *accept_lfn=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.:_/-";
00108 
00109         if (src_file==NULL) {
00110                 errno = SS_EINVALLFN;
00111                 return (-1);
00112         }
00113         // Verify length of destination lfn
00114         if (strlen (src_file) + 1 > LCG_MAXPATHLEN) {
00115                 errno = SS_ESOURCENAMETOOLONG;
00116                 return (-1);
00117         }
00118         if (vo == NULL) {
00119                 vo = getenv("LCG_GFAL_VO");
00120                 if (!vo) {
00121                         errno = SS_EINVALVO;
00122                         return (-1);
00123                 }
00124         }
00125         // Input file must be an LFN
00126         if (strncmp(src_file, "lfn:", 4) != 0) {
00127                 errno = SS_EINVALLFN;
00128                 return (-1);    
00129         }
00130         
00131         // Get default SE from Environment Variable
00132         char oo[strlen(vo)+1];
00133         char *storageelementdest;
00134         int i;
00135         strcpy(oo,vo);
00136         for (i=0; oo[i]!=0; i++)
00137                 oo[i] = toupper(oo[i]);
00138         storageelementdest = calloc(1, (strlen(oo)+strlen("VO_%s_DEFAULT_SE")+1));
00139         sprintf(storageelementdest,"VO_%s_DEFAULT_SE",oo);
00140         se = getenv(storageelementdest);
00141         free(storageelementdest);
00142         if ( aflag == 0 && se == NULL) {
00143                 errno = SS_EINVALSE;
00144                 return (-1);    
00145         }
00146         
00147         // Input parameters filter
00148         inv=0;
00149         inv = strspn(vo, accept_vo);
00150         if (inv != strlen(vo) ) {
00151                 errno = SS_EINVALVO;
00152                 return (-1);
00153         }
00154         inv=0;
00155         inv = strspn(src_file, accept_lfn);
00156         if (inv != strlen(src_file) ) {
00157                 errno = SS_EINVALLFN;
00158                 return (-1);
00159         }
00160         if (se != NULL) {
00161                 inv=0;
00162                 inv = strspn(se, accept_host);
00163                 if (inv != strlen(se) ) {
00164                         errno = SS_EINVALSE;
00165                         return (-1);
00166                 }
00167         }       
00168         
00169         // Add LFC_HOME to LFN
00170         if ( ss_get_lfchome(src_file, &src_file_new) < 0 ) {
00171                 int errno_save = errno;
00172                 errno = errno_save;
00173                 return (-1);                    
00174         }
00175         
00176         int existence = ss_check_lfn ( src_file_new, vo);
00177         int errno_save = errno;
00178         if ( existence < 0 ) {
00179                 free(src_file_new);
00180                 errno = errno_save;
00181                 return (-1);
00182         } else if ( existence == 0 ) {
00183                 free(src_file_new);
00184                 errno = SS_ENOENT;
00185                 return (-1);
00186         }
00187         
00188         if (aflag == 0) {
00189         char **pfns;
00190                 if ( lcg_lr(src_file_new, vo, conf_file, insecure, &pfns) < 0) {
00191                         int errno_save = errno;
00192                         free(src_file_new);
00193                         errno = errno_save;
00194                         return (-1);
00195                 }
00196                 // Verify if exist at least one replica
00197                 if (pfns[0] == NULL) {
00198                         free(pfns); free(src_file_new);
00199                         errno = SS_ENOENT;
00200                         return (-1);
00201                 } else if (pfns[1]== NULL) {
00202                         pfns[0]+=6;
00203                         int g = strcspn(se, "\n");
00204                         if (strncmp (pfns[0], se, g) != 0) {
00205                                 pfns[0]-=6;
00206                                 free(pfns[0]); free(pfns); free(src_file_new);
00207                                 errno = SS_ENOENT;
00208                                 return (-1);
00209                         }
00210                         deletekey=1;
00211                         pfns[0]-=6;
00212                 } else {
00213                         int x;
00214                         int found = 0;
00215                         for (x=0;pfns[x]!=NULL;x++) {
00216                                 pfns[x]+=6;
00217                                 int g = strcspn(se, "\n");
00218                                 if (strncmp (pfns[x], se, g) == 0) {
00219                                         found = 1;
00220                                         pfns[x]-=6;
00221                                         break;
00222                                 }
00223                                 pfns[x]-=6;
00224                         }
00225                         if (!found) {
00226                                 for(x=0;pfns[x]!=NULL;x++) {
00227                                         free(pfns[x]);
00228                                 }
00229                                 free(pfns); free(src_file_new);
00230                                 errno = SS_ENOENT;
00231                                 return (-1);
00232                         }
00233                         
00234                 }
00235         }
00236         
00237     if ( aflag == 1 || deletekey == 1) {
00238                 // DELETE KEY AND IV FROM KEYSTORE
00239                 if ( ss_delete_key(src_file_new) < 0) {
00240                         int errno_save = errno;
00241                         free(src_file_new);
00242                         errno = errno_save;
00243                         return (-1);
00244                 }       
00245     }
00246         
00247         if (lcg_delt (src_file_new, aflag, se, vo, conf_file, insecure, verbose, timeout) < 0) {
00248                 int errno_save = errno;
00249                 free(src_file_new);
00250                 errno = errno_save;
00251                 return (-1);
00252         }
00253         free(src_file_new);
00254         
00255         return (0);
00256 }

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