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 <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 }
00086 #endif
00087
00088
00089
00090 int insecure, verbose;
00091
00092 int helpflg;
00093
00094 const char *accept_host=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.-";
00095 const char *accept_vo=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789-";
00096 const char *accept_lfn=" abcdefghilmnopqrstuvzwyxkjABCDEFGHILMNOPQRSTUVZWYXKJ0123456789.:_/-";
00097
00098
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
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
00200 if (strncmp (src_file, "lfn:", 4) != 0) {
00201 fprintf (stderr, "Invalid lfn : %s \n", argv[optind]);
00202 exit(1);
00203 }
00204
00205
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
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
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 }