irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

icatAdminMS.cpp
Go to the documentation of this file.
1 
7 #include "rcMisc.h"
8 #include "generalAdmin.h"
9 #include "miscServerFunct.hpp"
11 #include "rodsErrorTable.h"
12 #include "rsGeneralAdmin.hpp"
13 #include "irods_re_structs.hpp"
14 #include "rodsLog.h"
15 
16 #define IRODS_FILESYSTEM_ENABLE_SERVER_SIDE_API
17 #include "filesystem.hpp"
18 
57  int i;
58 
59  std::string svc_role;
60  irods::error ret = get_catalog_service_role(svc_role);
61  if(!ret.ok()) {
62  irods::log(PASS(ret));
63  return ret.code();
64  }
65 
66  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
67  i = chlRegUserRE( rei->rsComm, rei->uoio );
68  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
70  } else {
71  rodsLog(
72  LOG_ERROR,
73  "role not supported [%s]",
74  svc_role.c_str() );
76  }
77  return i;
78 }
79 
113 int msiCreateCollByAdmin( msParam_t* xparColl, msParam_t* xchildName, ruleExecInfo_t *rei ) {
114  int i;
115  collInfo_t collInfo;
116  char *parColl;
117  char *childName;
118 
119  parColl = ( char * ) xparColl->inOutStruct;
120  childName = ( char * ) xchildName->inOutStruct;
121  memset( &collInfo, 0, sizeof( collInfo_t ) );
122  snprintf( collInfo.collName, sizeof( collInfo.collName ),
123  "%s/%s", parColl, childName );
124  snprintf( collInfo.collOwnerName, sizeof( collInfo.collOwnerName ),
125  "%s", rei->uoio->userName );
126  snprintf( collInfo.collOwnerZone, sizeof( collInfo.collOwnerZone ),
127  "%s", rei->uoio->rodsZone );
128 
129  std::string svc_role;
130  irods::error ret = get_catalog_service_role(svc_role);
131  if(!ret.ok()) {
132  irods::log(PASS(ret));
133  return ret.code();
134  }
135 
136  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
137  i = chlRegCollByAdmin( rei->rsComm, &collInfo );
138  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
140  } else {
141  rodsLog(
142  LOG_ERROR,
143  "role not supported [%s]",
144  svc_role.c_str() );
146  }
147  return i;
148 }
149 
183 int msiDeleteCollByAdmin( msParam_t* xparColl, msParam_t* xchildName, ruleExecInfo_t *rei ) {
184  int i;
185  collInfo_t collInfo;
186  memset(&collInfo, 0, sizeof(collInfo));
187  char *parColl;
188  char *childName;
189 
190  parColl = ( char * ) xparColl->inOutStruct;
191  childName = ( char * ) xchildName->inOutStruct;
192 
193  snprintf( collInfo.collName, sizeof( collInfo.collName ),
194  "%s/%s", parColl, childName );
195  snprintf( collInfo.collOwnerName, sizeof( collInfo.collOwnerName ),
196  "%s", rei->uoio->userName );
197  snprintf( collInfo.collOwnerZone, sizeof( collInfo.collOwnerZone ),
198  "%s", rei->uoio->rodsZone );
199 
200  std::string svc_role;
201  irods::error ret = get_catalog_service_role(svc_role);
202  if(!ret.ok()) {
203  irods::log(PASS(ret));
204  return ret.code();
205  }
206 
207  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
208  i = chlDelCollByAdmin( rei->rsComm, &collInfo );
209  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
211  } else {
212  rodsLog(
213  LOG_ERROR,
214  "role not supported [%s]",
215  svc_role.c_str() );
217  }
218 
219  if ( i == CAT_UNKNOWN_COLLECTION ) {
220  /* Not sure where this kind of logic belongs, chl, rules,
221  or here; but for now it's here. */
222  /* If the error is that it does not exist, return OK. */
223  freeRErrorContent( &rei->rsComm->rError ); /* remove suberrors if any */
224  return 0;
225  }
226  return i;
227 }
228 
260 int
262  int i;
263  std::string svc_role;
264  irods::error ret = get_catalog_service_role(svc_role);
265  if(!ret.ok()) {
266  irods::log(PASS(ret));
267  return ret.code();
268  }
269 
270  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
271  i = chlDelUserRE( rei->rsComm, rei->uoio );
272  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
274  } else {
275  rodsLog(
276  LOG_ERROR,
277  "role not supported [%s]",
278  svc_role.c_str() );
280  }
281  return i;
282 }
283 
316 int
318  int i;
319  char *groupName;
320  std::string svc_role;
321  irods::error ret = get_catalog_service_role(svc_role);
322  if(!ret.ok()) {
323  irods::log(PASS(ret));
324  return ret.code();
325  }
326 
327  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
328  if ( strncmp( rei->uoio->userType, "rodsgroup", 9 ) == 0 ) {
329  return 0;
330  }
331  groupName = ( char * ) msParam->inOutStruct;
332  i = chlModGroup( rei->rsComm, groupName, "add", rei->uoio->userName,
333  rei->uoio->rodsZone );
334  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
336  } else {
337  rodsLog(
338  LOG_ERROR,
339  "role not supported [%s]",
340  svc_role.c_str() );
342  }
343 
344  return i;
345 }
346 
380 int
382  int status;
383  std::string svc_role;
384  irods::error ret = get_catalog_service_role(svc_role);
385  if(!ret.ok()) {
386  irods::log(PASS(ret));
387  return ret.code();
388  }
389 
390  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
391  char *oldNameStr;
392  char *newNameStr;
393 
394  oldNameStr = ( char * ) oldName->inOutStruct;
395  newNameStr = ( char * ) newName->inOutStruct;
396  status = chlRenameLocalZone( rei->rsComm, oldNameStr, newNameStr );
397  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
399  } else {
400  rodsLog(
401  LOG_ERROR,
402  "role not supported [%s]",
403  svc_role.c_str() );
405  }
406  return status;
407 }
408 
442 int
444 {
445  std::string svc_role;
446 
447  if (irods::error ret = get_catalog_service_role(svc_role); !ret.ok()) {
448  irods::log(PASS(ret));
449  return ret.code();
450  }
451 
452  if (irods::CFG_SERVICE_ROLE_PROVIDER == svc_role) {
453  namespace fs = irods::experimental::filesystem;
454 
455  const fs::path src_path = static_cast<const char*>(oldName->inOutStruct);
456  const fs::path dst_path = static_cast<const char*>(newName->inOutStruct);
457 
458  try {
459  fs::server::rename(*rei->rsComm, src_path, dst_path);
460  }
461  catch (const fs::filesystem_error& e) {
462  rodsLog(LOG_ERROR, "msiRenameCollection failed: [%s]", e.what());
463  return e.code().value();
464  }
465  }
466  else if (irods::CFG_SERVICE_ROLE_CONSUMER == svc_role) {
467  return SYS_NO_RCAT_SERVER_ERR;
468  }
469  else {
470  rodsLog(LOG_ERROR, "role not supported [%s]", svc_role.c_str());
472  }
473 
474  return 0;
475 }
476 
513 int
515  char *inputArg;
516 
517  std::string svc_role;
518  irods::error ret = get_catalog_service_role(svc_role);
519  if(!ret.ok()) {
520  irods::log(PASS(ret));
521  return ret.code();
522  }
523 
524  std::string strict = "off";
525  inputArg = ( char * ) msParam->inOutStruct;
526  if ( inputArg != NULL ) {
527  if ( strncmp( inputArg, "STRICT", 6 ) == 0 ) {
528  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
530  strict = "on";
531  }
532  }
533  }
534  else {
535  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
537  }
538  }
539 
540  // set a strict acl prop
541  try {
542  irods::set_server_property<std::string>(irods::STRICT_ACL_KW, strict);
543  } catch ( irods::exception& e ) {
544  irods::log(e);
545  return e.code();
546  }
547 
548  return 0;
549 }
550 
551 
552 
590 int
592  generalAdminInp_t generalAdminInp; /* Input for rsGeneralAdmin */
593  char quota[21];
594  int status;
595 
596 
597  /* For testing mode when used with irule --test */
598  RE_TEST_MACRO( " Calling msiSetQuota" )
599 
600  /* Sanity checks */
601  if ( rei == NULL || rei->rsComm == NULL ) {
602  rodsLog( LOG_ERROR, "msiSetQuota: input rei or rsComm is NULL." );
604  }
605 
606 
607  /* Must be called from an admin account */
608  if ( rei->uoic->authInfo.authFlag < LOCAL_PRIV_USER_AUTH ) {
610  rodsLog( LOG_ERROR, "msiSetQuota: User %s is not local admin. Status = %d",
611  rei->uoic->userName, status );
612  return status;
613  }
614 
615 
616  /* Prepare generalAdminInp. It needs to be set up as follows:
617  * generalAdminInp.arg0: "set-quota"
618  * generalAdminInp.arg1: type ("user" or "group")
619  * generalAdminInp.arg2: name of user/group
620  * generalAdminInp.arg3: resource name or "total"
621  * generalAdminInp.arg4: quota value
622  * generalAdminInp.arg5: ""
623  * generalAdminInp.arg6: ""
624  * generalAdminInp.arg7: ""
625  * generalAdminInp.arg8: ""
626  * generalAdminInp.arg9: ""
627  */
628  memset( &generalAdminInp, 0, sizeof( generalAdminInp_t ) );
629  generalAdminInp.arg0 = "set-quota";
630 
631  /* Parse type */
632  if ( ( generalAdminInp.arg1 = parseMspForStr( type ) ) == NULL ) {
633  rodsLog( LOG_ERROR, "msiSetQuota: Null user or group type provided." );
635  }
636  if ( strcmp( generalAdminInp.arg1, "user" ) && strcmp( generalAdminInp.arg1, "group" ) ) {
638  rodsLog( LOG_ERROR, "msiSetQuota: Invalid user type: %s. Valid types are \"user\" and \"group\"",
639  generalAdminInp.arg1 );
640  return status;
641  }
642 
643  /* Parse user/group name */
644  if ( ( generalAdminInp.arg2 = parseMspForStr( name ) ) == NULL ) {
645  rodsLog( LOG_ERROR, "msiSetQuota: Null user or group name provided." );
647  }
648 
649  /* parse resource name */
650  if ( ( generalAdminInp.arg3 = parseMspForStr( resource ) ) == NULL ) {
651  generalAdminInp.arg3 = "total";
652  }
653 
654  /* Parse value */
655  if ( value->type && !strcmp( value->type, STR_MS_T ) ) {
656  generalAdminInp.arg4 = ( char * )value->inOutStruct;
657  }
658  else if ( value->type && !strcmp( value->type, INT_MS_T ) ) {
659  snprintf( quota, 11, "%d", *( int * )value->inOutStruct );
660  generalAdminInp.arg4 = quota;
661  }
662  else if ( value->type && !strcmp( value->type, DOUBLE_MS_T ) ) {
663  snprintf( quota, 21, "%lld", *( rodsLong_t * )value->inOutStruct );
664  generalAdminInp.arg4 = quota;
665  }
666  else {
668  rodsLog( LOG_ERROR, "msiSetQuota: Invalid type for param value. Status = %d", status );
669  return status;
670  }
671 
672  /* Fill up the rest of generalAdminInp */
673  generalAdminInp.arg5 = "";
674  generalAdminInp.arg6 = "";
675  generalAdminInp.arg7 = "";
676  generalAdminInp.arg8 = "";
677  generalAdminInp.arg9 = "";
678 
679 
680  /* Call rsGeneralAdmin */
681  status = rsGeneralAdmin( rei->rsComm, &generalAdminInp );
682 
683 
684  /* Done */
685  return status;
686 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
chlDelCollByAdmin
int chlDelCollByAdmin(rsComm_t *rsComm, collInfo_t *collInfo)
Definition: icatHighLevelRoutines.cpp:1774
NULL
#define NULL
Definition: rodsDef.h:70
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
msiDeleteCollByAdmin
int msiDeleteCollByAdmin(msParam_t *xparColl, msParam_t *xchildName, ruleExecInfo_t *rei)
Definition: icatAdminMS.cpp:183
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
irods_server_properties.hpp
msiDeleteUser
int msiDeleteUser(ruleExecInfo_t *rei)
Definition: icatAdminMS.cpp:261
generalAdminInp_t
Definition: generalAdmin.h:6
userInfo_t::userName
char userName[64]
Definition: rodsUser.h:66
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
generalAdminInp_t::arg6
const char * arg6
Definition: generalAdmin.h:13
SYS_NO_ICAT_SERVER_ERR
@ SYS_NO_ICAT_SERVER_ERR
Definition: rodsErrorTable.h:104
chlGenQueryAccessControlSetup
int chlGenQueryAccessControlSetup(const char *user, const char *zone, const char *host, int priv, int controlFlag)
Definition: icatHighLevelRoutines.cpp:4511
generalAdmin.h
msiSetQuota
int msiSetQuota(msParam_t *type, msParam_t *name, msParam_t *resource, msParam_t *value, ruleExecInfo_t *rei)
Definition: icatAdminMS.cpp:591
rcMisc.h
parseMspForStr
char * parseMspForStr(msParam_t *inpParam)
Definition: msParam.cpp:893
filesystem.hpp
CollInfo::collOwnerZone
char collOwnerZone[64]
Definition: objInfo.h:182
generalAdminInp_t::arg4
const char * arg4
Definition: generalAdmin.h:11
msiCreateUser
int msiCreateUser(ruleExecInfo_t *rei)
Definition: icatAdminMS.cpp:56
generalAdminInp_t::arg9
const char * arg9
Definition: generalAdmin.h:16
rsGeneralAdmin
int rsGeneralAdmin(rsComm_t *rsComm, generalAdminInp_t *generalAdminInp)
Definition: rsGeneralAdmin.cpp:183
INT_MS_T
#define INT_MS_T
Definition: msParam.h:22
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
generate_iadmin_commands_for_41_to_42_upgrade.name
name
Definition: generate_iadmin_commands_for_41_to_42_upgrade.py:23
generalAdminInp_t::arg0
const char * arg0
Definition: generalAdmin.h:7
msiAddUserToGroup
int msiAddUserToGroup(msParam_t *msParam, ruleExecInfo_t *rei)
Definition: icatAdminMS.cpp:317
CollInfo
Definition: objInfo.h:177
STR_MS_T
#define STR_MS_T
Definition: msParam.h:21
rsGeneralAdmin.hpp
RuleExecInfo::rsComm
rsComm_t * rsComm
Definition: irods_re_structs.hpp:22
generalAdminInp_t::arg3
const char * arg3
Definition: generalAdmin.h:10
generalAdminInp_t::arg7
const char * arg7
Definition: generalAdmin.h:14
CollInfo::collOwnerName
char collOwnerName[64]
Definition: objInfo.h:181
rsComm_t::rError
rError_t rError
Definition: rcConnect.h:158
irods::error::code
long long code() const
Definition: irods_error.cpp:194
CAT_UNKNOWN_COLLECTION
@ CAT_UNKNOWN_COLLECTION
Definition: rodsErrorTable.h:429
generalAdminInp_t::arg5
const char * arg5
Definition: generalAdmin.h:12
USER_BAD_KEYWORD_ERR
@ USER_BAD_KEYWORD_ERR
Definition: rodsErrorTable.h:246
irods::experimental::filesystem
Definition: collection_entry.hpp:12
CAT_INSUFFICIENT_PRIVILEGE_LEVEL
@ CAT_INSUFFICIENT_PRIVILEGE_LEVEL
Definition: rodsErrorTable.h:445
generalAdminInp_t::arg1
const char * arg1
Definition: generalAdmin.h:8
chlRenameLocalZone
int chlRenameLocalZone(rsComm_t *rsComm, const char *oldZoneName, const char *newZoneName)
Definition: icatHighLevelRoutines.cpp:1576
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
msiCreateCollByAdmin
int msiCreateCollByAdmin(msParam_t *xparColl, msParam_t *xchildName, ruleExecInfo_t *rei)
Definition: icatAdminMS.cpp:113
irods::STRICT_ACL_KW
const std::string STRICT_ACL_KW("strict_acls")
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
SYS_NO_RCAT_SERVER_ERR
@ SYS_NO_RCAT_SERVER_ERR
Definition: rodsErrorTable.h:110
LOCAL_PRIV_USER_AUTH
#define LOCAL_PRIV_USER_AUTH
Definition: rodsUser.h:36
get_irods_version.value
dictionary value
Definition: get_irods_version.py:27
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
userInfo_t::rodsZone
char rodsZone[64]
Definition: rodsUser.h:67
MsParam
Definition: msParam.h:76
rodsLog.h
irods::log
void log(const error &)
Definition: irods_log.cpp:13
msiRenameCollection
int msiRenameCollection(msParam_t *oldName, msParam_t *newName, ruleExecInfo_t *rei)
Definition: icatAdminMS.cpp:443
generalAdminInp_t::arg2
const char * arg2
Definition: generalAdmin.h:9
RuleExecInfo::uoio
userInfo_t * uoio
Definition: irods_re_structs.hpp:33
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
userInfo_t::userType
char userType[64]
Definition: rodsUser.h:68
chlRegUserRE
int chlRegUserRE(rsComm_t *rsComm, userInfo_t *userInfo)
Definition: icatHighLevelRoutines.cpp:2392
USER_PARAM_TYPE_ERR
@ USER_PARAM_TYPE_ERR
Definition: rodsErrorTable.h:254
chlDelUserRE
int chlDelUserRE(rsComm_t *rsComm, userInfo_t *userInfo)
Definition: icatHighLevelRoutines.cpp:1137
RuleExecInfo::uoic
userInfo_t * uoic
Definition: irods_re_structs.hpp:30
generalAdminInp_t::arg8
const char * arg8
Definition: generalAdmin.h:15
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
RuleExecInfo
Definition: irods_re_structs.hpp:18
irods_re_structs.hpp
RE_TEST_MACRO
#define RE_TEST_MACRO(msg)
Definition: reDefines.h:58
irods::exception
Definition: irods_exception.hpp:15
icatHighLevelRoutines.hpp
msiAclPolicy
int msiAclPolicy(msParam_t *msParam, ruleExecInfo_t *)
Definition: icatAdminMS.cpp:514
irods::experimental::filesystem::client::rename
auto rename(rcComm_t &_comm, const path &_from, const path &_to) -> void
Definition: filesystem.cpp:805
rodsErrorTable.h
chlModGroup
int chlModGroup(rsComm_t *rsComm, const char *groupName, const char *option, const char *userName, const char *userZone)
Definition: icatHighLevelRoutines.cpp:2164
userInfo_t::authInfo
authInfo_t authInfo
Definition: rodsUser.h:70
MsParam::inOutStruct
void * inOutStruct
Definition: msParam.h:80
DOUBLE_MS_T
#define DOUBLE_MS_T
Definition: msParam.h:27
authInfo_t::authFlag
int authFlag
Definition: rodsUser.h:42
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
chlRegCollByAdmin
int chlRegCollByAdmin(rsComm_t *rsComm, collInfo_t *collInfo)
Definition: icatHighLevelRoutines.cpp:1190
type
int type
Definition: filesystem.cpp:103
msiRenameLocalZone
int msiRenameLocalZone(msParam_t *oldName, msParam_t *newName, ruleExecInfo_t *rei)
Definition: icatAdminMS.cpp:381
CollInfo::collName
char collName[(1024+64)]
Definition: objInfo.h:179
freeRErrorContent
int freeRErrorContent(rError_t *myError)
Definition: rcMisc.cpp:182
rodsLong_t
long long rodsLong_t
Definition: rodsType.h:32