00001
00002
00003
00004
00005
00006 #include "generalAdmin.h"
00007 #include "reGlobalsExtern.h"
00008 #include "icatHighLevelRoutines.h"
00009
00010 int
00011 rsGeneralAdmin (rsComm_t *rsComm, generalAdminInp_t *generalAdminInp )
00012 {
00013 rodsServerHost_t *rodsServerHost;
00014 int status;
00015
00016 rodsLog(LOG_DEBUG, "generalAdmin");
00017
00018 status = getAndConnRcatHost(rsComm, MASTER_RCAT, NULL, &rodsServerHost);
00019 if (status < 0) {
00020 return(status);
00021 }
00022
00023 if (rodsServerHost->localFlag == LOCAL_HOST) {
00024 #ifdef RODS_CAT
00025 status = _rsGeneralAdmin (rsComm, generalAdminInp);
00026 #else
00027 status = SYS_NO_RCAT_SERVER_ERR;
00028 #endif
00029 }
00030 else {
00031 status = rcGeneralAdmin(rodsServerHost->conn,
00032 generalAdminInp);
00033 if (status < 0) {
00034 replErrorStack (rodsServerHost->conn->rError, &rsComm->rError);
00035 }
00036 }
00037 if (status < 0) {
00038 rodsLog (LOG_NOTICE,
00039 "rsGeneralAdmin: rcGeneralAdmin error %d", status);
00040 }
00041 return (status);
00042 }
00043
00044 #ifdef RODS_CAT
00045 int
00046 _rsGeneralAdmin(rsComm_t *rsComm, generalAdminInp_t *generalAdminInp )
00047 {
00048 int status;
00049 userInfo_t userInfo;
00050 collInfo_t collInfo;
00051 rescInfo_t rescInfo;
00052 ruleExecInfo_t rei;
00053 char *args[MAX_NUM_OF_ARGS_IN_ACTION];
00054 int i, argc;
00055 ruleExecInfo_t rei2;
00056
00057 memset ((char*)&rei2, 0, sizeof (ruleExecInfo_t));
00058 rei2.rsComm = rsComm;
00059 if (rsComm != NULL) {
00060 rei2.uoic = &rsComm->clientUser;
00061 rei2.uoip = &rsComm->proxyUser;
00062 }
00063
00064 rodsLog (LOG_DEBUG,
00065 "_rsGeneralAdmin arg0=%s",
00066 generalAdminInp->arg0);
00067
00068 if (strcmp(generalAdminInp->arg0,"pvacuum")==0) {
00069 char *args[2];
00070 char argStr[100];
00071 memset((char*)&rei,0,sizeof(rei));
00072 rei.rsComm = rsComm;
00073 rei.uoic = &rsComm->clientUser;
00074 rei.uoip = &rsComm->proxyUser;
00075 rstrcpy(argStr,"",sizeof argStr);
00076 if (atoi(generalAdminInp->arg1) > 0) {
00077 snprintf(argStr,sizeof argStr,"<ET>%s</ET>",generalAdminInp->arg1);
00078 }
00079 if (atoi(generalAdminInp->arg2) > 0) {
00080 strncat(argStr,"<EF>",100);
00081 strncat(argStr,generalAdminInp->arg2,100);
00082 strncat(argStr,"</EF>",100);
00083 }
00084 args[0]=argStr;
00085 status = applyRuleArg("acVacuum", args, 1, &rei, SAVE_REI);
00086 return(status);
00087 }
00088
00089 if (strcmp(generalAdminInp->arg0,"add")==0) {
00090 if (strcmp(generalAdminInp->arg1,"user")==0) {
00091
00092 char *args[2];
00093 memset((char*)&rei,0,sizeof(rei));
00094 rei.rsComm = rsComm;
00095 strncpy(userInfo.userName, generalAdminInp->arg2,
00096 sizeof userInfo.userName);
00097 strncpy(userInfo.userType, generalAdminInp->arg3,
00098 sizeof userInfo.userType);
00099 strncpy(userInfo.rodsZone, generalAdminInp->arg4,
00100 sizeof userInfo.rodsZone);
00101 strncpy(userInfo.authInfo.authStr, generalAdminInp->arg5,
00102 sizeof userInfo.authInfo.authStr);
00103 rei.uoio = &userInfo;
00104 rei.uoic = &rsComm->clientUser;
00105 rei.uoip = &rsComm->proxyUser;
00106 status = applyRuleArg("acCreateUser", args, 0, &rei, SAVE_REI);
00107 if (status != 0) chlRollback(rsComm);
00108 return(status);
00109 }
00110 if (strcmp(generalAdminInp->arg1,"dir")==0) {
00111 memset((char*)&collInfo,0,sizeof(collInfo));
00112 strncpy(collInfo.collName, generalAdminInp->arg2,
00113 sizeof collInfo.collName);
00114 if (strlen(generalAdminInp->arg3) > 0) {
00115 strncpy(collInfo.collOwnerName, generalAdminInp->arg3,
00116 sizeof collInfo.collOwnerName);
00117 status = chlRegCollByAdmin(rsComm, &collInfo);
00118 if (status == 0) {
00119 int status2;
00120 status2 = chlCommit(rsComm);
00121 }
00122 }
00123 else {
00124 status = chlRegColl(rsComm, &collInfo);
00125 }
00126 if (status != 0) chlRollback(rsComm);
00127 return(status);
00128 }
00129 if (strcmp(generalAdminInp->arg1,"zone")==0) {
00130 status = chlRegZone(rsComm, generalAdminInp->arg2,
00131 generalAdminInp->arg3,
00132 generalAdminInp->arg4,
00133 generalAdminInp->arg5);
00134 if (status == 0) {
00135 if (strcmp(generalAdminInp->arg3,"remote")==0) {
00136 memset((char*)&collInfo,0,sizeof(collInfo));
00137 strncpy(collInfo.collName, "/", sizeof collInfo.collName);
00138 strncat(collInfo.collName, generalAdminInp->arg2,
00139 sizeof collInfo.collName);
00140 strncpy(collInfo.collOwnerName, rsComm->proxyUser.userName,
00141 sizeof collInfo.collOwnerName);
00142 status = chlRegCollByAdmin(rsComm, &collInfo);
00143 if (status == 0) {
00144 chlCommit(rsComm);
00145 }
00146 }
00147 }
00148 return(status);
00149 }
00150 if (strcmp(generalAdminInp->arg1,"resource")==0) {
00151 strncpy(rescInfo.rescName, generalAdminInp->arg2,
00152 sizeof rescInfo.rescName);
00153 strncpy(rescInfo.rescType, generalAdminInp->arg3,
00154 sizeof rescInfo.rescType);
00155 strncpy(rescInfo.rescClass, generalAdminInp->arg4,
00156 sizeof rescInfo.rescClass);
00157 strncpy(rescInfo.rescLoc, generalAdminInp->arg5,
00158 sizeof rescInfo.rescLoc);
00159 strncpy(rescInfo.rescVaultPath, generalAdminInp->arg6,
00160 sizeof rescInfo.rescVaultPath);
00161 strncpy(rescInfo.zoneName, generalAdminInp->arg7,
00162 sizeof rescInfo.zoneName);
00163
00164 args[0] = rescInfo.rescName;
00165 args[1] = rescInfo.rescType;
00166 args[2] = rescInfo.rescClass;
00167 args[3] = rescInfo.rescLoc;
00168 args[4] = rescInfo.rescVaultPath;
00169 args[5] = rescInfo.zoneName;
00170 argc = 6;
00171 i = applyRuleArg("acPreProcForCreateResource", args, argc, &rei2, NO_SAVE_REI);
00172 if (i < 0) {
00173 if (rei2.status < 0) {
00174 i = rei2.status;
00175 }
00176 rodsLog (LOG_ERROR,
00177 "rsGeneralAdmin:acPreProcForCreateResource error for %s,stat=%d",
00178 rescInfo.rescName,i);
00179 return i;
00180 }
00181
00182
00183 status = chlRegResc(rsComm, &rescInfo);
00184 if (status != 0) {
00185 chlRollback(rsComm);
00186 return(status);
00187 }
00188
00189
00190 i = applyRuleArg("acPostProcForCreateResource",args,argc, &rei2, NO_SAVE_REI);
00191 if (i < 0) {
00192 if (rei2.status < 0) {
00193 i = rei2.status;
00194 }
00195 rodsLog (LOG_ERROR,
00196 "rsGeneralAdmin:acPostProcForCreateResource error for %s,stat=%d",
00197 rescInfo.rescName,i);
00198 return i;
00199 }
00200
00201
00202 return(status);
00203 }
00204 if (strcmp(generalAdminInp->arg1,"token")==0) {
00205
00206
00207 args[0] = generalAdminInp->arg2;
00208 args[1] = generalAdminInp->arg3;
00209 args[2] = generalAdminInp->arg4;
00210 args[3] = generalAdminInp->arg5;
00211 args[4] = generalAdminInp->arg6;
00212 args[5] = generalAdminInp->arg7;
00213 argc = 6;
00214 i = applyRuleArg("acPreProcForCreateToken", args, argc, &rei2, NO_SAVE_REI);
00215 if (i < 0) {
00216 if (rei2.status < 0) {
00217 i = rei2.status;
00218 }
00219 rodsLog (LOG_ERROR,
00220 "rsGeneralAdmin:acPreProcForCreateToken error for %s.%s=%s,stat=%d",
00221 args[0],args[1],args[2],i);
00222 return i;
00223 }
00224
00225
00226 status = chlRegToken(rsComm, generalAdminInp->arg2,
00227 generalAdminInp->arg3,
00228 generalAdminInp->arg4,
00229 generalAdminInp->arg5,
00230 generalAdminInp->arg6,
00231 generalAdminInp->arg7);
00232
00233 if (status == 0) {
00234 i = applyRuleArg("acPostProcForCreateToken", args, argc, &rei2, NO_SAVE_REI);
00235 if (i < 0) {
00236 if (rei2.status < 0) {
00237 i = rei2.status;
00238 }
00239 rodsLog (LOG_ERROR,
00240 "rsGeneralAdmin:acPostProcForCreateToken error for %s.%s=%s,stat=%d",
00241 args[0],args[1],args[2],i);
00242 return i;
00243 }
00244 }
00245
00246
00247 if (status != 0) chlRollback(rsComm);
00248 return(status);
00249 }
00250 if (strcmp(generalAdminInp->arg1,"specificQuery")==0) {
00251 status = chlAddSpecificQuery(rsComm, generalAdminInp->arg2,
00252 generalAdminInp->arg3);
00253 return(status);
00254 }
00255 }
00256 if (strcmp(generalAdminInp->arg0,"modify")==0) {
00257 if (strcmp(generalAdminInp->arg1,"user")==0) {
00258
00259 args[0] = generalAdminInp->arg2;
00260 args[1] = generalAdminInp->arg3;
00261 #if 0
00262 args[2] = generalAdminInp->arg4;
00263 #else
00264
00265
00266
00267
00268
00269 args[2] = "obfuscatedPw";
00270 #endif
00271 argc = 3;
00272 i = applyRuleArg("acPreProcForModifyUser",args,argc, &rei2, NO_SAVE_REI);
00273 if (i < 0) {
00274 if (rei2.status < 0) {
00275 i = rei2.status;
00276 }
00277 rodsLog (LOG_ERROR,
00278 "rsGeneralAdmin:acPreProcForModifyUser error for %s and option %s,stat=%d",
00279 args[0],args[1], i);
00280 return i;
00281 }
00282
00283
00284 status = chlModUser(rsComm, generalAdminInp->arg2,
00285 generalAdminInp->arg3, generalAdminInp->arg4);
00286
00287
00288 if (status == 0) {
00289 i = applyRuleArg("acPostProcForModifyUser",args,argc, &rei2, NO_SAVE_REI);
00290 if (i < 0) {
00291 if (rei2.status < 0) {
00292 i = rei2.status;
00293 }
00294 rodsLog (LOG_ERROR,
00295 "rsGeneralAdmin:acPostProcForModifyUser error for %s and option %s,stat=%d",
00296 args[0],args[1], i);
00297 return i;
00298 }
00299 }
00300
00301 if (status != 0) chlRollback(rsComm);
00302 return(status);
00303 }
00304 if (strcmp(generalAdminInp->arg1,"group")==0) {
00305
00306 args[0] = generalAdminInp->arg2;
00307 args[1] = generalAdminInp->arg3;
00308 args[2] = generalAdminInp->arg4;
00309 args[3] = generalAdminInp->arg5;
00310 argc = 4;
00311 i = applyRuleArg("acPreProcForModifyUserGroup",args,argc, &rei2, NO_SAVE_REI);
00312 if (i < 0) {
00313 if (rei2.status < 0) {
00314 i = rei2.status;
00315 }
00316 rodsLog (LOG_ERROR,
00317 "rsGeneralAdmin:acPreProcForModifyUserGroup error for %s and option %s,stat=%d",
00318 args[0],args[1], i);
00319 return i;
00320 }
00321
00322
00323 status = chlModGroup(rsComm, generalAdminInp->arg2,
00324 generalAdminInp->arg3, generalAdminInp->arg4,
00325 generalAdminInp->arg5);
00326
00327 if (status == 0) {
00328 i = applyRuleArg("acPostProcForModifyUserGroup",args,argc, &rei2, NO_SAVE_REI);
00329 if (i < 0) {
00330 if (rei2.status < 0) {
00331 i = rei2.status;
00332 }
00333 rodsLog (LOG_ERROR,
00334 "rsGeneralAdmin:acPostProcForModifyUserGroup error for %s and option %s,stat=%d",
00335 args[0],args[1], i);
00336 return i;
00337 }
00338 }
00339
00340
00341 if (status != 0) chlRollback(rsComm);
00342 return(status);
00343 }
00344 if (strcmp(generalAdminInp->arg1,"zone")==0) {
00345 status = chlModZone(rsComm, generalAdminInp->arg2,
00346 generalAdminInp->arg3, generalAdminInp->arg4);
00347 if (status != 0) chlRollback(rsComm);
00348 if (status == 0 &&
00349 strcmp(generalAdminInp->arg3, "name")==0) {
00350 char oldName[MAX_NAME_LEN];
00351 char newName[MAX_NAME_LEN];
00352 strncpy(oldName, "/", sizeof oldName);
00353 strncat(oldName, generalAdminInp->arg2, sizeof oldName);
00354 strncpy(newName, generalAdminInp->arg4, sizeof newName);
00355 status = chlRenameColl(rsComm, oldName, newName);
00356 if (status==0) chlCommit(rsComm);
00357 }
00358 return(status);
00359 }
00360 if (strcmp(generalAdminInp->arg1,"localzonename")==0) {
00361
00362 char *args[2];
00363 memset((char*)&rei,0,sizeof(rei));
00364 rei.rsComm = rsComm;
00365 memset((char*)&rei,0,sizeof(rei));
00366 rei.rsComm = rsComm;
00367 rei.uoic = &rsComm->clientUser;
00368 rei.uoip = &rsComm->proxyUser;
00369 args[0]=generalAdminInp->arg2;
00370 args[1]=generalAdminInp->arg3;
00371 status = applyRuleArg("acRenameLocalZone", args, 2, &rei,
00372 NO_SAVE_REI);
00373 return(status);
00374 }
00375 if (strcmp(generalAdminInp->arg1,"resource")==0) {
00376
00377 args[0] = generalAdminInp->arg2;
00378 args[1] = generalAdminInp->arg3;
00379 args[2] = generalAdminInp->arg4;
00380 argc = 3;
00381 i = applyRuleArg("acPreProcForModifyResource",args,argc, &rei2, NO_SAVE_REI);
00382 if (i < 0) {
00383 if (rei2.status < 0) {
00384 i = rei2.status;
00385 }
00386 rodsLog (LOG_ERROR,
00387 "rsGeneralAdmin:acPreProcForModifyResource error for %s and option %s,stat=%d",
00388 args[0],args[1], i);
00389 return i;
00390 }
00391
00392
00393 status = chlModResc(rsComm, generalAdminInp->arg2,
00394 generalAdminInp->arg3, generalAdminInp->arg4);
00395
00396
00397 if (status == 0) {
00398 i = applyRuleArg("acPostProcForModifyResource",args,argc, &rei2, NO_SAVE_REI);
00399 if (i < 0) {
00400 if (rei2.status < 0) {
00401 i = rei2.status;
00402 }
00403 rodsLog (LOG_ERROR,
00404 "rsGeneralAdmin:acPostProcForModifyResource error for %s and option %s,stat=%d",
00405 args[0],args[1], i);
00406 return i;
00407 }
00408 }
00409
00410
00411 if (status != 0) chlRollback(rsComm);
00412 return(status);
00413 }
00414 if (strcmp(generalAdminInp->arg1,"resourcegroup")==0) {
00415
00416 args[0] = generalAdminInp->arg2;
00417 args[1] = generalAdminInp->arg3;
00418 args[2] = generalAdminInp->arg4;
00419 argc = 3;
00420 i = applyRuleArg("acPreProcForModifyResourceGroup",args,argc, &rei2, NO_SAVE_REI);
00421 if (i < 0) {
00422 if (rei2.status < 0) {
00423 i = rei2.status;
00424 }
00425 rodsLog (LOG_ERROR,
00426 "rsGeneralAdmin:acPreProcForModifyResourceGroup error for %s and option %s,stat=%d",
00427 args[0],args[1], i);
00428 return i;
00429 }
00430
00431
00432 status = chlModRescGroup(rsComm, generalAdminInp->arg2,
00433 generalAdminInp->arg3, generalAdminInp->arg4);
00434
00435
00436 if (status == 0) {
00437 i = applyRuleArg("acPostProcForModifyResourceGroup",args,argc, &rei2, NO_SAVE_REI);
00438 if (i < 0) {
00439 if (rei2.status < 0) {
00440 i = rei2.status;
00441 }
00442 rodsLog (LOG_ERROR,
00443 "rsGeneralAdmin:acPostProcForModifyResourceGroup error for %s and option %s,stat=%d",
00444 args[0],args[1], i);
00445 return i;
00446 }
00447 }
00448
00449
00450 if (status != 0) chlRollback(rsComm);
00451 return(status);
00452 }
00453 }
00454 if (strcmp(generalAdminInp->arg0,"rm")==0) {
00455 if (strcmp(generalAdminInp->arg1,"user")==0) {
00456
00457 char *args[2];
00458 memset((char*)&rei,0,sizeof(rei));
00459 rei.rsComm = rsComm;
00460 strncpy(userInfo.userName, generalAdminInp->arg2,
00461 sizeof userInfo.userName);
00462 strncpy(userInfo.rodsZone, generalAdminInp->arg3,
00463 sizeof userInfo.rodsZone);
00464 rei.uoio = &userInfo;
00465 rei.uoic = &rsComm->clientUser;
00466 rei.uoip = &rsComm->proxyUser;
00467 status = applyRuleArg("acDeleteUser", args, 0, &rei, SAVE_REI);
00468 if (status != 0) chlRollback(rsComm);
00469 return(status);
00470 }
00471 if (strcmp(generalAdminInp->arg1,"dir")==0) {
00472 memset((char*)&collInfo,0,sizeof(collInfo));
00473 strncpy(collInfo.collName, generalAdminInp->arg2,
00474 sizeof collInfo.collName);
00475 status = chlDelColl(rsComm, &collInfo);
00476 if (status != 0) chlRollback(rsComm);
00477 return(status);
00478 }
00479 if (strcmp(generalAdminInp->arg1,"resource")==0) {
00480
00481
00482
00483
00484 if ( strcmp( generalAdminInp->arg3, "--dryrun" ) == 0 ) {
00485 strncpy( rescInfo.rescName, generalAdminInp->arg2, sizeof rescInfo.rescName );
00486 rodsLog( LOG_STATUS, "Executing a dryrun of removal of resource [%s]", generalAdminInp->arg2 );
00487
00488 status = chlDelResc( rsComm, &rescInfo, 1 );
00489 if( 0 == status ) {
00490 rodsLog( LOG_STATUS, "DRYRUN REMOVING RESOURCE [%s] :: SUCCESS", generalAdminInp->arg2 );
00491 } else {
00492 rodsLog( LOG_STATUS, "DRYRUN REMOVING RESOURCE [%s] :: FAILURE", generalAdminInp->arg2 );
00493 }
00494
00495 return status;
00496 }
00497
00498
00499 strncpy(rescInfo.rescName, generalAdminInp->arg2,
00500 sizeof rescInfo.rescName);
00501
00502
00503 args[0] = rescInfo.rescName;
00504 argc = 1;
00505 i = applyRuleArg("acPreProcForDeleteResource", args, argc, &rei2, NO_SAVE_REI);
00506 if (i < 0) {
00507 if (rei2.status < 0) {
00508 i = rei2.status;
00509 }
00510 rodsLog (LOG_ERROR,
00511 "rsGeneralAdmin:acPreProcForDeleteResource error for %s,stat=%d",
00512 rescInfo.rescName,i);
00513 return i;
00514 }
00515
00516
00517 status = chlDelResc(rsComm, &rescInfo);
00518 if (status == 0) {
00519
00520 i = applyRuleArg("acPostProcForDeleteResource",args,argc, &rei2, NO_SAVE_REI);
00521 if (i < 0) {
00522 if (rei2.status < 0) {
00523 i = rei2.status;
00524 }
00525 rodsLog (LOG_ERROR,
00526 "rsGeneralAdmin:acPostProcForDeleteResource error for %s,stat=%d",
00527 rescInfo.rescName,i);
00528 return i;
00529 }
00530 }
00531
00532
00533 if (status != 0) chlRollback(rsComm);
00534 return(status);
00535 }
00536 if (strcmp(generalAdminInp->arg1,"zone")==0) {
00537 status = chlDelZone(rsComm, generalAdminInp->arg2);
00538 if (status == 0) {
00539 memset((char*)&collInfo,0,sizeof(collInfo));
00540 strncpy(collInfo.collName, "/", sizeof collInfo.collName);
00541 strncat(collInfo.collName, generalAdminInp->arg2,
00542 sizeof collInfo.collName);
00543 status = chlDelCollByAdmin(rsComm, &collInfo);
00544 }
00545 if (status == 0) {
00546 status = chlCommit(rsComm);
00547 }
00548 return(status);
00549 }
00550 if (strcmp(generalAdminInp->arg1,"token")==0) {
00551
00552
00553 args[0] = generalAdminInp->arg2;
00554 args[1] = generalAdminInp->arg3;
00555 argc = 2;
00556 i = applyRuleArg("acPreProcForDeleteToken", args, argc, &rei2, NO_SAVE_REI);
00557 if (i < 0) {
00558 if (rei2.status < 0) {
00559 i = rei2.status;
00560 }
00561 rodsLog (LOG_ERROR,
00562 "rsGeneralAdmin:acPreProcForDeleteToken error for %s.%s,stat=%d",
00563 args[0],args[1],i);
00564 return i;
00565 }
00566
00567
00568 status = chlDelToken(rsComm, generalAdminInp->arg2,
00569 generalAdminInp->arg3);
00570
00571
00572 if (status == 0) {
00573 i = applyRuleArg("acPostProcForDeleteToken", args, argc, &rei2, NO_SAVE_REI);
00574 if (i < 0) {
00575 if (rei2.status < 0) {
00576 i = rei2.status;
00577 }
00578 rodsLog (LOG_ERROR,
00579 "rsGeneralAdmin:acPostProcForDeleteToken error for %s.%s,stat=%d",
00580 args[0],args[1],i);
00581 return i;
00582 }
00583 }
00584
00585
00586 if (status != 0) chlRollback(rsComm);
00587 return(status);
00588 }
00589 if (strcmp(generalAdminInp->arg1,"unusedAVUs")==0) {
00590 status = chlDelUnusedAVUs(rsComm);
00591 return(status);
00592 }
00593 if (strcmp(generalAdminInp->arg1,"specificQuery")==0) {
00594 status = chlDelSpecificQuery(rsComm, generalAdminInp->arg2);
00595 return(status);
00596 }
00597 }
00598 if (strcmp(generalAdminInp->arg0,"calculate-usage")==0) {
00599 status = chlCalcUsageAndQuota(rsComm);
00600 return(status);
00601 }
00602 if (strcmp(generalAdminInp->arg0,"set-quota")==0) {
00603 status = chlSetQuota(rsComm,
00604 generalAdminInp->arg1,
00605 generalAdminInp->arg2,
00606 generalAdminInp->arg3,
00607 generalAdminInp->arg4);
00608
00609 return(status);
00610 }
00611 return(CAT_INVALID_ARGUMENT);
00612 }
00613 #endif