00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include <gacl.h>
00018
00019
00020
00021
00022
00023 #define SUCCESS 0
00024 #define FAILURE 1
00025 #define SEARCH_START_QUOTE 1
00026 #define SEARCH_END_QUOTE 2
00027 #define QUOTE_CHAR '\"'
00028 #define LINESIZE 5000
00029 #define MAXLINES 6000
00030 #define REM "#"
00031 #define DEFAULTOUTPUTFILE "output.gacl"
00032 #define PREFIX_VO "/VO="
00033 #define PREFIX_GROUP "/GROUP="
00034 #define PREFIX_SUBGROUP "/SUBGROUP="
00035 #define PREFIX_ROLE "/ROLE="
00036 #define PREFIX_CAPS "/CAPABILITY="
00037 #define PREFIX_SLASHSTAR "
00038
00039
00040
00041
00042
00043
00044
00045 void cleanupStatics (void);
00046 void showhelp (void);
00047 int strclean (char **s);
00048 int strnclean (char **s, int bufsize);
00049 int handle_parameters (int argc, char **argv);
00050 int handle_gridmapfile (char * gridmapfile, GACLacl **acl);
00051 int handle_groupmapfile(char * groupmapfile, GACLacl **acl);
00052 int getdnfromvo (char *vo, char ***dn, int *count);
00053
00054
00055
00056
00057
00058
00059 int strsepvoms (const char *voms, char **result, const char *prefix);
00060
00061 int filetest();
00062
00063
00064
00065 typedef struct {
00066 char *vo;
00067 char *dn;
00068 } dnvoms_s;
00069
00070 static char *gridmapfile = NULL;
00071 static char *vomapfile = NULL;
00072 static char *groupmapfile = NULL;
00073 static char *gaclfile = NULL;
00074 static int verboselevel = 0;
00075 static dnvoms_s *dnvoms = NULL;
00076 static int dnvoms_cnt = 0;
00077 static int with_star = 0;
00078 static int with_slash_star = 0;
00079 static int warning = 0;
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 int main (int argc,
00095 char **argv)
00096 {
00097 GACLacl *acl = NULL;
00098
00099
00100 if (handle_parameters(argc, argv) != SUCCESS)
00101 {
00102 return FAILURE;
00103 }
00104
00105 if (verboselevel > 0)
00106 {
00107 printf("Parameters successfully gathered\n");
00108 }
00109
00110
00111 if (filetest() != SUCCESS)
00112 return FAILURE;
00113
00114
00115 GACLinit();
00116
00117 acl = GACLnewAcl();
00118
00119 if (gridmapfile != NULL)
00120 handle_gridmapfile(gridmapfile, &acl);
00121
00122 if (groupmapfile != NULL)
00123 handle_groupmapfile(groupmapfile, &acl);
00124
00125 if (vomapfile != NULL)
00126 handle_groupmapfile(vomapfile, &acl);
00127
00128 if ( (gridmapfile != NULL) ||
00129 (groupmapfile != NULL) ||
00130 (vomapfile != NULL) )
00131 GACLsaveAcl(gaclfile, acl);
00132
00133
00134
00135
00136
00137
00138
00139 if (verboselevel > 0)
00140 printf ("Program ended successfully\n");
00141
00142
00143 GACLfreeAcl(acl);
00144 free(acl);
00145 cleanupStatics();
00146
00147 return SUCCESS;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 void cleanupStatics ()
00161 {
00162 int i = 0;
00163
00164 if (gridmapfile != NULL)
00165 free(gridmapfile);
00166
00167 if (vomapfile != NULL)
00168 free(vomapfile);
00169
00170 if (groupmapfile != NULL)
00171 free(groupmapfile);
00172
00173 if ( (strncmp(gaclfile, DEFAULTOUTPUTFILE, strlen(DEFAULTOUTPUTFILE)) != 0) &&
00174 (gaclfile != NULL) )
00175 free(gaclfile);
00176
00177 for (i = 0; i < dnvoms_cnt; i++)
00178 {
00179 free((dnvoms[i]).vo);
00180 free((dnvoms[i]).dn);
00181 }
00182 free(dnvoms);
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 int handle_gridmapfile (char * gridmapfile, GACLacl **acl)
00197 {
00198 GACLcred *cred = NULL;
00199 GACLentry *entry = NULL;
00200 FILE *gridmap = NULL;
00201 int i = 0;
00202 char **lines = NULL;
00203 char **dn = NULL;
00204 int linecount = 0;
00205 int dncount = 0;
00206
00207 gridmap = fopen(gridmapfile, "r");
00208
00209 if (gridmap == NULL)
00210 {
00211 printf("Error: gridmapfile \"%s\" cannot be opened.\n", gridmapfile);
00212 return FAILURE;
00213 }
00214
00215
00216 lines = NULL; // The first run must be set to NULL
00217 linecount = 0; // The first run must start at zero
00218
00219 do
00220 {
00221 linecount++;
00222
00223
00224 lines = (char **) realloc (lines, (sizeof(char *) * linecount));
00225
00226
00227 lines[linecount - 1] = (char *) malloc (sizeof(char) * LINESIZE);
00228 }
00229 while (fgets(lines[linecount - 1], LINESIZE, gridmap) != NULL);
00230
00231
00232
00233 fclose(gridmap);
00234
00235
00236 for (i = 0; i < linecount; i++)
00237 {
00238 // No space plz
00239 lines[i] += strspn(lines[i], VO_DATA_WHITESPACE_CHARS);
00240
00241 // Clear a empty line
00242 if (strlen(lines[i]) <= 1)
00243 {
00244 continue;
00245 }
00246
00247 // Clear lines prefixing a REM block (usually '#')
00248 if (strncmp(strtok(lines[i], "\"\n"), REM, strlen(REM)) != 0)
00249 {
00250 dn = realloc (dn, (sizeof(char *) * ++dncount));
00251 dn[dncount - 1] = malloc(sizeof(char) * LINESIZE);
00252
00253 dn[dncount - 1] = strtok(lines[i], "\"\n");
00254 }
00255 }
00256
00257
00258 if (verboselevel > 1)
00259 {
00260 for (i = 0; i < dncount; i++)
00261 {
00262 printf("%s\n", dn[i]);
00263 }
00264 }
00265
00266 for (i = 0; i < dncount; i++)
00267 {
00268 if (strncmp("/VO", dn[i], strlen("/VO")) != 0)
00269 {
00270 cred = GACLnewCred("person");
00271 GACLaddToCred(cred, "dn", dn[i]);
00272
00273 entry = GACLnewEntry();
00274 GACLaddCred(entry, cred);
00275
00276 GACLallowPerm(entry, GACL_PERM_READ);
00277 GACLallowPerm(entry, GACL_PERM_WRITE);
00278
00279 GACLdenyPerm(entry, GACL_PERM_ADMIN);
00280
00281 GACLaddEntry(*acl, entry);
00282 }
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 if (verboselevel > 2)
00303 printf("End Marker Parsing and cleaning\n");
00304
00305 // End
00306 return SUCCESS;
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 int handle_groupmapfile (char * groupmapfile, GACLacl **acl)
00322 {
00323 GACLcred *cred = NULL;
00324 GACLentry *entry = NULL;
00325 FILE *groupmap = NULL;
00326 int i = 0;
00327 int t = 0;
00328 char **lines = NULL;
00329 char **vo = NULL;
00330 int linecount = 0;
00331 int vocount = 0;
00332
00333
00334 char *sepvo = NULL;
00335 char *sepgroup = NULL;
00336 char *sepsubgroup = NULL;
00337 char *seprole = NULL;
00338 char *sepcaps = NULL;
00339
00340
00341
00342
00343
00344
00345
00346 char **voms = 0;
00347 int count = 0;
00348
00349
00350 groupmap = fopen(groupmapfile, "r");
00351
00352
00353 if (groupmap == NULL)
00354 {
00355 printf("Error: groupmapfile \"%s\" cannot be opened.\n", groupmapfile);
00356 return FAILURE;
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 do
00368 {
00369 linecount++;
00370
00371
00372 lines = (char **) realloc (lines, (sizeof(char *) * linecount));
00373
00374
00375 lines[linecount - 1] = (char *) malloc (sizeof(char) * LINESIZE);
00376 }
00377 while (fgets(lines[linecount - 1], LINESIZE, groupmap) != NULL);
00378
00379
00380
00381 fclose(groupmap);
00382
00383
00384
00385 for (i = 0; i < linecount; i++)
00386 {
00387 // No space plz
00388 lines[i] += strspn(lines[i], VO_DATA_WHITESPACE_CHARS);
00389
00390 // Clear a empty line
00391 if (strlen(lines[i]) <= 1)
00392 {
00393 continue;
00394 }
00395
00396 // Clear lines prefixing a REM block (usually '#')
00397 if (strncmp(strtok(lines[i], "\"\n"), REM, strlen(REM)) != 0)
00398 {
00399 vo = realloc (vo, (sizeof(char *) * ++vocount));
00400 vo[vocount - 1] = malloc(sizeof(char) * LINESIZE);
00401
00402 vo[vocount - 1] = strtok(lines[i], "\"\n");
00403 }
00404 }
00405
00406
00407
00408 if (verboselevel > 0)
00409 {
00410 for (i = 0; i < vocount; i++)
00411 {
00412 printf("%s\n", vo[i]);
00413 }
00414 }
00415
00416 sepvo = (char *) malloc(sizeof(char) * LINESIZE);
00417 sepgroup = (char *) malloc(sizeof(char) * LINESIZE);
00418 sepsubgroup = (char *) malloc(sizeof(char) * LINESIZE);
00419 seprole = (char *) malloc(sizeof(char) * LINESIZE);
00420 sepcaps = (char *) malloc(sizeof(char) * LINESIZE);
00421
00422
00423
00424 for (i = 0; i < vocount; i++)
00425 {
00426 if (strncmp("/VO", vo[i], strlen("/VO")) == 0)
00427 {
00428
00429 strnclean (&sepvo, LINESIZE);
00430 strnclean (&sepgroup, LINESIZE);
00431 strnclean (&sepsubgroup, LINESIZE);
00432 strnclean (&seprole, LINESIZE);
00433 strnclean (&sepcaps, LINESIZE);
00434
00435
00436 strsepvoms(vo[i], &sepvo, "/VO=");
00437 strsepvoms(vo[i], &sepgroup, "/GROUP=");
00438 strsepvoms(vo[i], &sepsubgroup, "/SUBGROUP=");
00439 strsepvoms(vo[i], &seprole, "/ROLE=");
00440 strsepvoms(vo[i], &sepcaps, "/CAPABILITY=");
00441
00442 if (voms != NULL)
00443 {
00444 for (t = 0; t < count; t++)
00445 {
00446 strclean(&(voms[t]));
00447 free(voms[t]);
00448 }
00449 free(voms);
00450 voms = NULL;
00451 }
00452
00453 if (getdnfromvo (sepvo, &voms, &count) == SUCCESS)
00454 {
00455 for (t = 0; t < count; t++)
00456 {
00457 cred = GACLnewCred("voms-cred");
00458
00459 GACLaddToCred(cred, "voms", voms[t]);
00460
00461 if (strlen(sepvo) > 0)
00462 GACLaddToCred(cred, "vo", sepvo);
00463 if (strlen(sepgroup) > 0)
00464 GACLaddToCred(cred, "group", sepgroup);
00465 if (strlen(sepsubgroup) > 0)
00466 GACLaddToCred(cred, "subgroup", sepsubgroup);
00467 if (strlen(seprole) > 0)
00468 GACLaddToCred(cred, "role", seprole);
00469 if (strlen(sepcaps) > 0)
00470 GACLaddToCred(cred, "capability", sepcaps);
00471
00472 entry = GACLnewEntry();
00473 GACLaddCred(entry, cred);
00474 GACLallowPerm(entry, GACL_PERM_READ);
00475 GACLallowPerm(entry, GACL_PERM_WRITE);
00476
00477 GACLdenyPerm(entry, GACL_PERM_ADMIN);
00478
00479 GACLaddEntry(*acl, entry);
00480 }
00481 }
00482 else
00483 {
00484 if (!warning)
00485 printf("Warning: This entry with VO '%s' contains no data about the DN of the VOMS server.\n", sepvo);
00486
00487 cred = GACLnewCred("voms-cred");
00488
00489 // GACLaddToCred(cred, "voms", vo[i]); // No knowledge yet about which VOMS server should be inserted here
00490 // GACLaddToCred(cred, "voms", "");
00491
00492 if (strlen(sepvo) > 0)
00493 GACLaddToCred(cred, "vo", sepvo);
00494 if (strlen(sepgroup) > 0)
00495 GACLaddToCred(cred, "group", sepgroup);
00496 if (strlen(sepsubgroup) > 0)
00497 GACLaddToCred(cred, "subgroup", sepsubgroup);
00498 if (strlen(seprole) > 0)
00499 GACLaddToCred(cred, "role", seprole);
00500 if (strlen(sepcaps) > 0)
00501 GACLaddToCred(cred, "capability", sepcaps);
00502
00503 entry = GACLnewEntry();
00504 GACLaddCred(entry, cred);
00505 GACLallowPerm(entry, GACL_PERM_READ);
00506 GACLallowPerm(entry, GACL_PERM_WRITE);
00507
00508 GACLdenyPerm(entry, GACL_PERM_LIST);
00509 GACLdenyPerm(entry, GACL_PERM_ADMIN);
00510
00511 GACLaddEntry(*acl, entry);
00512 }
00513
00514 strnclean (&sepvo, LINESIZE);
00515 strnclean (&sepgroup, LINESIZE);
00516 strnclean (&sepsubgroup, LINESIZE);
00517 strnclean (&seprole, LINESIZE);
00518 strnclean (&sepcaps, LINESIZE);
00519 }
00520 }
00521
00522 free(sepvo);
00523 free(sepgroup);
00524 free(sepsubgroup);
00525 free(seprole);
00526 free(sepcaps);
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 if (verboselevel > 2)
00548 printf("End Marker Parsing and cleaning\n");
00549
00550 return SUCCESS;
00551 }
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573 int strsepvoms (const char *voms, char **result, const char *prefix)
00574 {
00575 int i = 0;
00576 char *tmpvoms = NULL;
00577 char *tmpresult = NULL;
00578 char *oldtmpvoms = NULL;
00579
00580 tmpvoms = strdup(voms);
00581 tmpresult = (char *) malloc(sizeof(char) * LINESIZE);
00582 strnclean(&tmpresult, LINESIZE);
00583
00584 // debug
00585 oldtmpvoms = tmpvoms;
00586
00587 do
00588 {
00589 // Determine case-insensitive if the prefix is at the beginning of the string
00590 if (strncasecmp(tmpvoms, prefix, strlen(prefix)) == 0)
00591 {
00592 if (verboselevel > 3)
00593 printf("Prefix \"%s\" found, stepping over prefix string\n", prefix);
00594
00595 // Stepping over prefix
00596 for (i = 0; i < strlen(prefix); i++)
00597 {
00598 tmpvoms++;
00599 }
00600
00601 // Determining the length of the found string by searching for an end character
00602 i = 0;
00603 while (tmpvoms[i] != '\0')
00604 {
00605 if (strlen(tmpvoms) - i >= (strlen(PREFIX_VO)))
00606 {
00607 if (strncmp(PREFIX_VO, &tmpvoms[i], strlen(PREFIX_VO)) == 0)
00608 {
00609 // You have found the end character of the wanted substring
00610 break;
00611 }
00612 }
00613
00614 if (strlen(tmpvoms) - i >= (strlen(PREFIX_GROUP)))
00615 {
00616 if (strncmp(PREFIX_GROUP, &tmpvoms[i], strlen(PREFIX_GROUP)) == 0)
00617 {
00618 break;
00619 }
00620 }
00621
00622 if (strlen(tmpvoms) - i >= (strlen(PREFIX_SUBGROUP)))
00623 {
00624 if (strncmp(PREFIX_SUBGROUP, &tmpvoms[i], strlen(PREFIX_SUBGROUP)) == 0)
00625 {
00626 break;
00627 }
00628 }
00629
00630 if (strlen(tmpvoms) - i >= (strlen(PREFIX_ROLE)))
00631 {
00632 if (strncmp(PREFIX_ROLE, &tmpvoms[i], strlen(PREFIX_ROLE)) == 0)
00633 {
00634 break;
00635 }
00636 }
00637
00638 if (strlen(tmpvoms) - i >= (strlen(PREFIX_CAPS)))
00639 {
00640 if (strncmp(PREFIX_CAPS, &tmpvoms[i], strlen(PREFIX_CAPS)) == 0)
00641 {
00642 break;
00643 }
00644 }
00645
00646 // if the cmdline parameter -with_slash_star is set it will add the star behind the group name
00647 // like VOMS : /GROUP=fred
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724 void showhelp ()
00725 {
00726 printf("\n");
00727 printf("\t-gridmapfile <filepath> - Handles a 'gridmapfile' or 'grid-mapfile' as \n");
00728 printf("\t we use it with for local- and poolaccount\n");
00729 printf("\t-groupmapfile <filepath> - Handles a 'groupmapfile' with VO-GROUP-ROLEs and\n");
00730 printf("\t map-information for the local- and poolgroups\n");
00731 // printf("\t-vomapfile <filepath> - Handles a 'vomapfile' (this information is sometimes\n");
00732 // printf("\t at the end of a 'gridmapfile') containing\n");
00733 // printf("\t VO-GROUP-ROLE map-information to poolaccounts\n");
00734 printf("\t-gaclfile <filepath> - Assigned output file (default: '%s')\n", DEFAULTOUTPUTFILE);
00735 printf("\t-vomsdn <VO> <voms dn> - Overrides the DN with <voms dn> for every entry that is\n");
00736 printf("\t assosiated with the VO <VO> of the voms server\n");
00737 printf("\t NOTE: a VO can have multiple voms servers\n");
00738 printf("\t-v[v[v[v]]] - Extra diagnostic information\n");
00739 printf("\t NOTE: a verboselevel above 1 will trigger a file check\n");
00740 printf("\t a verboselevel above 3 will give extra parsing information\n");
00741 printf("\t-with_star - When this parameter is set, the GACL file will include the wildcard\n");
00742 printf("\t in the credential part of the ACL Entry.\n");
00743 printf("\t NOTE: this is for all known VOMS credential types: VO, GROUP, SUBGROUP, ROLE or CAPABILITY\n");
00744 printf("\t-with_slash_star - When this parameter is set, the GACL file will include the wildcard\n");
00745 printf("\t in the credential part of the ACL Entry.\n");
00746 printf("\t NOTE: this is for all known VOMS credential types: VO, GROUP, SUBGROUP, ROLE or CAPABILITY\n");
00747 printf("\t-nowarn - Skips the warning messages if they do not indicate an error.\n");
00748 printf("\n");
00749 }
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 int handle_parameters (int argc, char **argv)
00764 {
00765 int i;
00766
00767
00768
00769
00770
00771 if (!(argc > 1))
00772 {
00773 printf("Error: no parameters found, nothing to do...\n");
00774 showhelp();
00775
00776 return FAILURE;
00777 }
00778
00779 for (i = 1; i < argc; i++)
00780 {
00781 if ( (strcmp(argv[i], "-vomsdn") == 0) && (i + 2< argc))
00782 {
00783 if ((argv[i + 1] != NULL) &&
00784 (strlen(argv[i + 1]) > 0) &&
00785 (argv[i + 2] != NULL) &&
00786 (strlen(argv[i + 2]) > 0))
00787 {
00788 dnvoms = realloc(dnvoms, sizeof(dnvoms_s) * ++dnvoms_cnt);
00789 (dnvoms[dnvoms_cnt - 1]).vo = strdup(argv[i + 1]);
00790 (dnvoms[dnvoms_cnt - 1]).dn = strdup(argv[i + 2]);
00791
00792 }
00793 i += 2;;
00794
00795 }
00796
00797 else if ( (strcmp(argv[i], "-gridmapfile") == 0) && (i + 1 < argc))
00798 {
00799 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00800 {
00801 gridmapfile = strdup(argv[i + 1]);
00802 }
00803 i++;
00804 }
00805
00806 else if ( (strcmp(argv[i], "-groupmapfile") == 0) && (i + 1 < argc))
00807 {
00808 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00809 {
00810 groupmapfile = strdup(argv[i + 1]);
00811 }
00812 i++;
00813 }
00814
00815 else if ( (strcmp(argv[i], "-vomapfile") == 0) && (i + 1 < argc))
00816 {
00817 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00818 {
00819 vomapfile = strdup(argv[i + 1]);
00820 }
00821 i++;
00822 }
00823
00824 else if ( (strcmp(argv[i], "-gaclfile") == 0) && (i + 1 < argc))
00825 {
00826 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00827 {
00828 gaclfile = strdup(argv[i + 1]);
00829 }
00830 i++;
00831 }
00832
00833 else if (strncmp(argv[i], "-v", 2) == 0)
00834 {
00835 int j = 0;
00836
00837 verboselevel = 0;
00838 while (j < strlen(argv[i]))
00839 {
00840 if (((argv[i])[j]) == 'v')
00841 verboselevel++;
00842
00843 j++;
00844 }
00845 }
00846
00847 else if ( (strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-help") == 0) )
00848 {
00849 showhelp();
00850 }
00851
00852 else if ( (strcmp(argv[i], "-with_star") == 0) || (strcmp(argv[i], "-with-star") == 0) )
00853 {
00854 with_star = 1;
00855 }
00856
00857 else if ( (strcmp(argv[i], "-with_slash_star") == 0) || (strcmp(argv[i], "-with-slash-star") == 0) )
00858 {
00859 with_slash_star = 1;
00860 }
00861
00862 else if (strcmp(argv[i], "-nowarn") == 0)
00863 {
00864 warning = 1;
00865 }
00866
00867 else
00868 {
00869 printf("\n\tError: something is wrong with the parameters.\n");
00870 printf("\t The error has been detected on \"%s\"\n", argv[i]);
00871 printf("\t The last two parameters are : \"%s\" and \"%s\"\n\n", argv[i - 1], argv[i]);
00872 showhelp();
00873 return FAILURE;
00874 }
00875 }
00876
00877 if (verboselevel > 0)
00878 {
00879 printf("verbose level = %d\n", verboselevel);
00880 }
00881
00882 if (gaclfile == NULL)
00883 {
00884 gaclfile = DEFAULTOUTPUTFILE;
00885 }
00886
00887 if (verboselevel > 2)
00888 {
00889 printf("Files initialized as:\n");
00890 printf("-gridmapfile = %s\n", gridmapfile);
00891 printf("-groupmapfile = %s\n", groupmapfile);
00892 printf("-vomapfile = %s\n", vomapfile);
00893 printf("-gaclfile = %s\n", gaclfile);
00894 }
00895 else if ( (verboselevel > 0) && (verboselevel <= 2) )
00896 {
00897 printf("Output is set to: %s\n", gaclfile);
00898 }
00899
00900 if (verboselevel > 0)
00901 {
00902 for (i = 0; i < dnvoms_cnt; i++)
00903 printf("<VO> : %s \tis assosiated with \t<DN> : %s\n", (dnvoms[i]).vo, (dnvoms[i]).dn);
00904 }
00905
00906 return SUCCESS;
00907 }
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919 int filetest()
00920 {
00921 FILE *test = NULL;
00922
00923 if (gridmapfile != NULL)
00924 {
00925 if ((test = fopen(gridmapfile, "r")) != NULL)
00926 {
00927 if (verboselevel > 0)
00928 printf("Success: gridmapfile \"%s\" readable\n", gridmapfile);
00929
00930 fclose(test);
00931 }
00932 else
00933 {
00934 printf("Error: Can't open gridmapfile \"%s\"\n", gridmapfile);
00935 return FAILURE;
00936 }
00937 }
00938
00939 if (groupmapfile != NULL)
00940 {
00941 if ((test = fopen(groupmapfile, "r")) != NULL)
00942 {
00943 if (verboselevel > 0)
00944 printf("Success: groupmapfile \"%s\" readable\n", groupmapfile);
00945
00946 fclose(test);
00947 }
00948 else
00949 {
00950 printf("Error: Can't open groupmapfile \"%s\"\n", groupmapfile);
00951 return FAILURE;
00952 }
00953 }
00954
00955 if (vomapfile != NULL)
00956 {
00957 if ((test = fopen(vomapfile, "r")) != NULL)
00958 {
00959 if (verboselevel > 0)
00960 printf("Success: vomapfile \"%s\" readable\n", vomapfile);
00961
00962 fclose(test);
00963 }
00964 else
00965 {
00966 printf("Error: Can't open vomapfile \"%s\"\n", vomapfile);
00967 return FAILURE;
00968 }
00969 }
00970
00971 if (verboselevel > 1)
00972 {
00973 if (gaclfile != NULL)
00974 {
00975 if ((test = fopen(gaclfile, "r")) != NULL)
00976 fclose(test);
00977 else
00978 {
00979 printf("Warning: Can't open gaclfile \"%s\"\nA new gaclfile will be used.", gaclfile);
00980 }
00981 }
00982 }
00983
00984 return SUCCESS;
00985 }
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001 int strnclean (char **s, int bufsize)
01002 {
01003 int i = 0;
01004
01005 if (s == NULL)
01006 return FAILURE;
01007
01008 if (*s == NULL)
01009 return FAILURE;
01010
01011 for (i = 0; i < bufsize; i++)
01012 {
01013 (*s)[i] = '\0';
01014 }
01015
01016 return SUCCESS;
01017 }
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031 int strclean (char **s)
01032 {
01033 if (s == NULL)
01034 return FAILURE;
01035
01036 if (*s == NULL)
01037 return FAILURE;
01038
01039 if (strlen(*s) > 0)
01040 {
01041 int i = 0;
01042
01043 for (i = 0; i < strlen(*s); i++)
01044 (*s)[i] = '\0';
01045 }
01046
01047 return SUCCESS;
01048 }
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064 int getdnfromvo (char *vo, char ***dn, int *count)
01065 {
01066 int i;
01067 int resultvalue = FAILURE;
01068 char **tmp = NULL;
01069
01070 if (*dn != NULL)
01071 return FAILURE;
01072
01073 if (dnvoms_cnt < 1)
01074 return FAILURE;
01075
01076 *count = 0;
01077
01078 for (i = 0; i < dnvoms_cnt; i++)
01079 {
01080 if (strncmp((dnvoms[i]).vo, vo, strlen((dnvoms[i]).vo)) == 0)
01081 {
01082 tmp = (char **) realloc(*dn, ++(*count) * sizeof(char *));
01083
01084 tmp[*count - 1] = strdup((dnvoms[i]).dn);
01085 // *(dn[*count - 1]) = strdup((dnvoms[i]).dn);
01086
01087 *dn = tmp;
01088 resultvalue = SUCCESS;
01089 }
01090 }
01091 return resultvalue;
01092 }