-
Notifications
You must be signed in to change notification settings - Fork 12
/
uuGroup.r
1204 lines (1051 loc) · 34.3 KB
/
uuGroup.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# \file uuGroup.r
# \brief Functions for group management and group queries.
# \author Ton Smeele
# \author Chris Smeele
# \author Lazlo Westerhof
# \copyright Copyright (c) 2015-2021 Utrecht University. All rights reserved.
# \license GPLv3, see LICENSE.
# \brief Get the user type for a given user
#
# \param[in] user name of the irods user(#zone)
# \param[out] type usertype e.g. rodsuser, rodsgroup, rodsadmin
#
uuGetUserType(*user, *userType) {
*userType = "";
uuGetUserAndZone(*user, *userName, *userZone);
foreach (
*row in
SELECT USER_TYPE
WHERE USER_NAME = '*userName'
AND USER_ZONE = '*userZone'
) {
*userType = *row."USER_TYPE";
break;
}
}
# \brief Extract username and zone in separate fields.
#
# \param[in] user name of the irods user
# username can optionally include zone ('user#zone')
# default is to use the local zone
# \param[out] userName name of user exclusing zone information
# \param[out] userZone name of the zone of the user
#
uuGetUserAndZone(*user,*userName,*userZone) {
*userAndZone = split(*user, "#");
*userName = elem(*userAndZone,0);
if (size(*userAndZone) > 1) {
*userZone = elem(*userAndZone,1);
} else {
# FIXME: This is not necessarily the local zone.
# The local zone could be queried (ZONE_TYPE='local').
*userZone = $rodsZoneClient;
}
}
# \brief Retrieve the client zone name.
#
# \param[out] zoneName
#
uuClientZone(*zoneName) {
*zoneName = $rodsZoneClient;
}
uuClientFullName() = "$userNameClient#$rodsZoneClient";
# \brief Wrapper around uuClientFullName. Enables uuClientFullName to be called
# from the Python iRODS client
#
# \param[out] fullName
#
uuClientFullNameWrapper(*fullName) {
*fullName = uuClientFullName();
}
# \brief Check if a group category exists.
#
# \param[in] categoryName
# \param[out] exists
#
uuGroupCategoryExists(*categoryName, *exists) {
*exists = false;
foreach (
*row in
SELECT META_USER_ATTR_VALUE
WHERE USER_TYPE = 'rodsgroup'
AND META_USER_ATTR_NAME = 'category'
AND META_USER_ATTR_VALUE = '*categoryName'
) {
*exists = true;
}
}
# \brief Check if a rodsgroup with the given name exists.
#
# \param[in] groupName
# \param[out] exists
#
uuGroupExists(*groupName, *exists) {
*exists = false;
foreach (
*row in
SELECT USER_GROUP_NAME, USER_TYPE
WHERE USER_GROUP_NAME = '*groupName'
AND USER_TYPE = 'rodsgroup'
) {
*exists = true;
}
}
# \brief Check if a specific vault path already exists
#
# \param[in] vaultName
# \param[out] exists
#
uuGroupVaultPathExists(*vaultName, *exists) {
*exists = false;
*coll = "/$rodsZoneClient/home/" ++ *vaultName;
foreach(
*row in
SELECT COLL_NAME
WHERE COLL_NAME = *coll
) {
*exists = true;
}
}
# \brief Check if a user is a member of the given group.
#
# This is now a wrapper for the python function.
#
# \param[in] group name of the irods group
# \param[in] user name of the irods user
# username can optionally include zone ('user#zone')
# default is to use the local zone
# \param[in] includeRo whether to account for read-only memberships
# \param[out] membership true if user is a member of this group
#
uuGroupUserExists(*group, *user, *includeRo, *membership) {
*membership = "";
rule_group_user_exists(*group, *user, str(*includeRo), *membership);
if (*membership == "true") {
*membership = true;
} else {
*membership = false;
}
}
# \brief Check if the home collection belonging to a group is empty.
#
# \param[in] groupName group name (no zone)
# \param[out] empty
#
uuGroupCollIsEmpty(*groupName, *empty) {
*coll = "/$rodsZoneClient/home/*groupName";
*empty = true;
# rods will already be owner of a vault group collection, so no ACLs need
# to be changed.
foreach (*row in SELECT DATA_NAME WHERE COLL_NAME = '*coll') {
*empty = false; break;
}
if (*empty) {
foreach (*row in SELECT COLL_ID WHERE COLL_PARENT_NAME LIKE '*coll') {
*empty = false; break;
}
}
}
# \brief Check if a name is available in the iRODS username namespace.
#
# The username namespace includes names of the following user types:
#
# - rodsgroup
# - rodsadmin
# - rodsuser
# - domainadmin
# - groupadmin
# - storageadmin
# - rodscurators
#
# \param[in] name
# \param[out] available
# \param[out] existingType set to the USER_TYPE if the name is unavailable
#
uuUserNameIsAvailable(*name, *available, *existingType) {
*available = true;
*existingType = ".";
uuGetUserAndZone(*name, *userName, *userZone);
foreach (
*row in
SELECT USER_NAME, USER_ZONE, USER_TYPE
WHERE USER_NAME = '*userName'
AND USER_ZONE = '*userZone'
) {
*available = false;
*existingType = *row."USER_TYPE";
break;
}
}
# \brief List all groups the user belongs to.
#
# This result list will include any 'read-*' groups that the user is a member
# of. If this is not desirable, use uuUserGetGroups() instead.
#
# \param[in] user name of the irods user
# username can optionally include zone ('user#zone')
# default is to use the local zone
# \param[out] groups irods list of groupnames
#
uuGroupMemberships(*user, *groupList) {
uuGetUserAndZone(*user,*userName,*userZone);
*groups = "";
foreach (*row in SELECT USER_GROUP_NAME, USER_GROUP_ID
WHERE USER_NAME = '*userName' AND USER_ZONE = '*userZone') {
msiGetValByKey(*row,"USER_GROUP_NAME",*group);
# workasround needed: iRODS returns username also as a group !!
if (*group != *userName) {
*groups = "*groups:*group";
}
}
*groups = triml(*groups,":");
*groupList = split(*groups, ":");
}
# \brief Remove an empty vault and any revision collection of a research/intake group that no longer exists.
#
# This will fail if (1) The given vault does not exist,
# or (2) The corresponding research/intake group still exists.
#
# If the vault group is non-empty, it will not be removed, and the rule will succeed.
#
# \param[in] vaultName the group name of the vault to remove
#
uuGroupRemoveOrphanVaultIfEmpty(*vaultName) {
msiExecCmd("admin-remove-orphan-vault-if-empty.sh",
uuClientFullName ++ " " ++ *vaultName,
"", "", 0, *out);
msiGetStdoutInExecCmdOut(*out, *stdout);
writeString("stdout", "*stdout");
}
# \brief List all groups the user belongs to.
#
# This function has special handling for 'read-*' groups:
#
# If *includeRo is true, any groups that the user is a read-only member of will
# be returned. E.g. if the user is a member of 'read-test', either
# 'intake-test' or 'research-test' will be returned.
#
# The 'read-...' group names themselves are never included in the result list,
# regardless of the *includeRo parameter.
#
# \param[in] user name of the irods user
# \param[in] includeRo whether to include groups that the user has read-only access to
# \param[out] groups list of group names
#
uuUserGetGroups(*user, *includeRo, *groups) {
uuGetUserAndZone(*user, *userName, *userZone);
*groups = list();
*readGroups = list(); # Groups that start with 'read-'.
foreach (*row in
SELECT USER_GROUP_NAME
WHERE USER_NAME = '*userName'
AND USER_ZONE = '*userZone'){
*groupName = *row.'USER_GROUP_NAME';
if (*groupName != *userName) {
if (*groupName like "read-*") {
# Save 'read-' groups for later processing.
*readGroups = cons(*groupName, *readGroups);
} else {
*groups = cons(*groupName, *groups);
}
}
}
if (*includeRo) {
# Map 'read-' groups to their non-read names.
foreach (*roGroupName in *readGroups) {
uuGetBaseGroup(*roGroupName, *baseGroup);
*groups = cons(*baseGroup, *groups);
}
}
}
# \brief Map 'read-|vault-' groups to their 'intake-|research-|deposit-' counterparts.
#
# If no base group exists, the input *groupName is returned as *baseGroup.
#
# \param[in] groupName
# \param[out] baseGroup the base group name
#
uuGetBaseGroup(*groupName, *baseGroup) {
*baseGroup = "";
if (*groupName like regex "(read|vault)-.*") {
uuChop(*groupName, *_, *baseName, "-", true);
foreach (*row in
SELECT USER_GROUP_NAME
WHERE USER_GROUP_NAME LIKE '%-*baseName'){
*baseLikeGroup = *row.'USER_GROUP_NAME';
if (*baseLikeGroup like regex "(intake|research|deposit)-*baseName") {
*baseGroup = *baseLikeGroup;
break;
}
}
}
if (*baseGroup == "") {
# Apparently this group has no counterpart.
# (or perhaps this isn't a read-|vault- group after all)
*baseGroup = *groupName;
}
}
# \brief Get a list of all rodsgroups.
#
# \param[out] groupList list of groupnames
#
uuGetAllGroups(*groupList) {
*groups = "";
foreach (
*row in
SELECT USER_GROUP_NAME
WHERE USER_TYPE = 'rodsgroup'
) {
*groupName = *row."USER_GROUP_NAME";
if (strlen(*groups) > 0) {
*groups = "*groups,*groupName";
} else {
*groups = *groupName;
}
}
*groupList = split(*groups, ",");
}
# \brief Get a list of group subcategories for the given category.
#
# \param[in] category a category name
# \param[out] subcategories a list of subcategory names
#
uuGroupGetSubcategories(*category, *subcategories) {
*subcategories = list();
foreach (
# Get groups that belong to this category...
*categoryGroupRow in
SELECT USER_GROUP_NAME
WHERE USER_TYPE = 'rodsgroup'
AND META_USER_ATTR_NAME = 'category'
AND META_USER_ATTR_VALUE = '*category'
) {
*groupName = *categoryGroupRow."USER_GROUP_NAME";
foreach (
# ... and collect their subcategories.
*subcategoryRow in
SELECT META_USER_ATTR_VALUE
WHERE USER_TYPE = 'rodsgroup'
AND USER_GROUP_NAME = '*groupName'
AND META_USER_ATTR_NAME = 'subcategory'
) {
*subcategoryName = *subcategoryRow."META_USER_ATTR_VALUE";
uuListContains(*subcategories, *subcategoryName, *seen);
if (!*seen) {
*subcategories = cons(*subcategoryName, *subcategories);
}
}
}
}
# \brief Get a list of group categories.
#
# \param[out] categories a list of category names
#
uuGroupGetCategories(*categories) {
*categories = list();
foreach (
*category in
SELECT META_USER_ATTR_VALUE
WHERE USER_TYPE = 'rodsgroup'
AND META_USER_ATTR_NAME = 'category'
) {
*categories = cons(*category."META_USER_ATTR_VALUE", *categories);
}
}
# \brief Get a group's category and subcategory.
#
# \param[in] groupName
# \param[out] category
# \param[out] subcategory
#
uuGroupGetCategory(*groupName, *category, *subcategory) {
*category = "";
*subcategory = "";
foreach (
*catitem in
SELECT META_USER_ATTR_NAME, META_USER_ATTR_VALUE
WHERE USER_GROUP_NAME = '*groupName'
AND META_USER_ATTR_NAME = 'category'
) {
*category = *catitem."META_USER_ATTR_VALUE";
}
foreach (
*subcatitem in
SELECT META_USER_ATTR_NAME, META_USER_ATTR_VALUE
WHERE USER_GROUP_NAME = '*groupName'
AND META_USER_ATTR_NAME = 'subcategory'
) {
*subcategory = *subcatitem."META_USER_ATTR_VALUE";
}
}
# \brief Get a group's description.
#
# \param[in] groupName
# \param[out] description
#
uuGroupGetDescription(*groupName, *description) {
*description = "";
foreach (
*item in
SELECT META_USER_ATTR_VALUE
WHERE USER_GROUP_NAME = '*groupName'
AND META_USER_ATTR_NAME = 'description'
) {
if (*item."META_USER_ATTR_VALUE" != ".") {
*description = *item."META_USER_ATTR_VALUE";
}
}
}
# \brief Get a list of both manager and non-manager members of a group.
#
# This function ignores zone names, this is usually a bad idea.
#
# \deprecated Use uuGroupGetMembers(*groupName, *includeRo, *addTypePrefix, *members) instead
#
# \param[in] groupName
# \param[out] members a list of user names
#
uuGroupGetMembers(*groupName, *members) {
uuGroupGetMembers(*groupName, false, false, *m);
*members = list();
foreach (*member in *m) {
# Throw away the zone name for backward compat.
uuChop(*member, *name, *_, "#", true);
*members = cons(*name, *members);
}
}
# \brief Get a list of a group's members.
#
# If addTypePrefix is true, usernames will be prefixed with 'r:', 'n:',
# or 'm:', if they are, respectively, a read-only member, normal
# member, or a manager of the given group.
#
# \param[in] groupName
# \param[in] includeRo whether to include members with read-only access
# \param[in] addTypePrefix whether to prefix user names with the type of member they are (see below)
# \param[out] members a list of user names, including their zone names
#
uuGroupGetMembers(*groupName, *includeRo, *addTypePrefix, *members) {
*members = list();
# Fetch managers.
uuGroupGetManagers(*groupName, *managers);
foreach (*manager in *managers) {
*members = cons(if *addTypePrefix then "m:*manager" else "*manager", *members);
}
# Fetch normal members.
foreach (
*member in
SELECT USER_NAME,
USER_ZONE
WHERE USER_GROUP_NAME = '*groupName'
AND USER_TYPE != 'rodsgroup'
) {
*name = *member."USER_NAME";
*zone = *member."USER_ZONE";
uuListMatches(*members, "(m:)?*name#*zone", *isAlsoManager);
if (!*isAlsoManager) {
*members = cons(if *addTypePrefix then "n:*name#*zone" else "*name#*zone", *members);
}
}
# Fetch read-only members.
if (*includeRo && *groupName like regex ``(research|intake)-.+``) {
uuChop(*groupName, *_, *groupBaseName, '-', true);
foreach (
*member in
SELECT USER_NAME,
USER_ZONE
WHERE USER_GROUP_NAME == 'read-*groupBaseName'
AND USER_TYPE != 'rodsgroup'
) {
*name = *member."USER_NAME";
*zone = *member."USER_ZONE";
uuListMatches(*members, "([mn]:)?*name#*zone", *isNonRoMember);
if (!*isNonRoMember) {
*members = cons(if *addTypePrefix then "r:*name#*zone" else "*name#*zone", *members);
}
}
}
}
# \brief Get a group's member count.
#
# \param[in] groupName
# \param[out] members number of members of group
#
uuGroupGetMemberCount(*groupName, *members) {
*count = 0;
# Fetch members.
foreach (
*member in
SELECT USER_NAME,
USER_ZONE
WHERE USER_GROUP_NAME = '*groupName'
AND USER_TYPE != 'rodsgroup'
) {
*count = *count + 1;
}
# Fetch read-only members.
if (*groupName like regex ``(research|intake)-.+``) {
uuChop(*groupName, *_, *groupBaseName, '-', true);
foreach (
*member in
SELECT USER_NAME,
USER_ZONE
WHERE USER_GROUP_NAME == 'read-*groupBaseName'
AND USER_TYPE != 'rodsgroup'
) {
*count = *count + 1;
}
}
*members = int(*count);
}
# \brief Get a list of managers for the given group.
#
# \param[in] groupName
# \param[out] managers
#
uuGroupGetManagers(*groupName, *managers) {
*managers = list();
foreach (
*manager in
SELECT META_USER_ATTR_VALUE
WHERE USER_GROUP_NAME = '*groupName'
AND META_USER_ATTR_NAME = 'manager'
) {
# For backward compatibility, let zone be $rodsZoneClient if
# it's not present in metadata.
uuGetUserAndZone(*manager."META_USER_ATTR_VALUE", *name, *zone);
# Verify that this manager is actually a member of the group.
# (this is necessary for a.o. the groupUserAdd policy to work correctly
# when creating a new group)
uuGroupUserExists(*groupName, "*name#*zone", false, *isMember);
if (*isMember) {
*managers = cons("*name#*zone", *managers);
}
}
}
# \brief Find users matching a pattern.
#
# \param[in] query
# \param[out] users a list of user names
#
uuFindUsers(*query, *users) {
*userList = list();
*queryUser = *query;
*queryZone = "";
if (*query like "*#*") {
# Use the user and zone part as separate wildcard-surrounded query
# parts.
uuChop(*query, *queryUser, *queryZone, "#", true);
}
foreach (
*user in
SELECT USER_NAME, USER_ZONE
WHERE USER_TYPE = 'rodsuser'
AND USER_NAME LIKE '%*queryUser%'
AND USER_ZONE LIKE '%*queryZone%'
) {
*userList = cons(*user."USER_NAME" ++ "#" ++ *user."USER_ZONE", *userList);
}
foreach (
*user in
SELECT USER_NAME, USER_ZONE
WHERE USER_TYPE = 'rodsadmin'
AND USER_NAME LIKE '%*queryUser%'
AND USER_ZONE LIKE '%*queryZone%'
) {
*userList = cons(*user."USER_NAME" ++ "#" ++ *user."USER_ZONE", *userList);
}
uuJoin(',', *userList, *users)
}
# \brief Check if a user is a manager in the given group.
#
# \param[in] groupName
# \param[in] user
# \param[out] isManager
#
uuGroupUserIsManager(*groupName, *user, *isManager) {
*isManager = false;
uuGetUserAndZone(*user, *name, *zone);
*fullName = "*name#*zone";
if (*groupName like "read-*") {
uuGetBaseGroup(*groupName, *baseGroup);
if (*baseGroup != *groupName) {
# Check manager status on the base group instead.
uuGroupUserIsManager(*baseGroup, *fullName, *isManager);
}
} else {
uuGroupUserExists(*groupName, *fullName, false, *isMember);
if (*isMember) {
foreach (
*manager in
SELECT META_USER_ATTR_VALUE
WHERE USER_GROUP_NAME = '*groupName'
AND META_USER_ATTR_NAME = 'manager'
AND META_USER_ATTR_VALUE = '*fullName'
) {
*isManager = true;
}
}
}
}
# \brief Get a user's member role type.
#
# \param[in] groupName the group name
# \param[in] user the member name, optionally including their zone name
# \param[out] type the type of member, one of 'none', 'reader', 'normal' or 'manager'
#
uuGroupGetMemberType(*groupName, *user, *type) {
# {{{
# For some great inexplicable reason, the following is completely broken:
# {
#uuGetUserAndZone(*user, *userName, *userZone);
#writeLine("serverLog", "*user -> *userName # *userZone");
#uuGroupGetMembers(*groupName, true, true, *members);
#writeLine("serverLog", "*user -> *userName # *userZone");
# }
# The above call to uuGroupGetMembers OVERWRITES *userName with a different
# one, even though *userName is not even a parameter to that function.
# This has happened consistently when this rule is called as part of
# demoting a user (normal -> reader) from the group management portal.
# Unfortunately, I can't reproduce it via irule when calling this rule
# directly.
# As a workaround..... use a different variable name for userName and userZone.
# Yes. That fixes it. Don't ask me why.
# {
uuGetUserAndZone(*user, *userName1, *userZone1);
uuGroupGetMembers(*groupName, true, true, *members);
*userName = *userName1;
*userZone = *userZone1;
# }
# }}}
*type = "none";
foreach (*member in *members) {
uuChop(*member, *typeLetter, *member, ":", true);
if (*member == "*userName#*userZone") {
if (*typeLetter == "r") { *type = "reader"; }
else if (*typeLetter == "m") { *type = "manager"; }
else { *type = "normal"; }
break;
}
}
}
# Privileged group management functions {{{
# \brief Create a group.
#
# \param[in] groupName
# \param[out] status '0' on success, non-zero on failure - as string value!
# \param[out] message a user friendly error message, may contain the reason why an action was disallowed
#
uuGroupAdd(*groupName, *category, *subcategory, *schema_id, *expiration_date, *description, *dataClassification, *co_identifier, *status, *message) {
*status = '0';
*message = "An internal error occurred";
# Safeguard the maximum length of a group
*nameLength = strlen(*groupName);
if (*nameLength > 63) {
*status = '999';
*message = "The groupname '*groupName' is too long (" ++ str(*nameLength) ++ "). The maximum allowed number of characters is 63";
succeed;
}
if (*description == "") {
# XXX This exact workaround exists in the `uuGroupModify` rule as well.
# If you change this block, change it there too.
# Work around an iRODS bug that causes errors when changing metadata
# values to an empty string in specific situations.
# 'description' is currently the only property that can be set to empty
# by the user, and we handle that case here.
*description = ".";
# This dot must be treated specially (as an empty string) in query
# functions.
}
*kv."category" = *category;
*kv."subcategory" = *subcategory;
*kv."schema_id" = *schema_id;
*kv."expiration_date" = *expiration_date;
*kv."description" = *description;
*kv."data_classification" = *dataClassification;
*kv."co_identifier" = *co_identifier;
# Shoot first, ask questions later.
*status = str(errorcode(msiSudoGroupAdd(*groupName, "manager", uuClientFullName, "", *kv)));
if (*status == '0') {
*message = "";
} else {
# Why didn't you allow me to do that?
uuGroupPolicyCanGroupAdd(
uuClientFullName,
*groupName,
*category,
*subcategory,
*expiration_date,
*schema_id,
*description,
*dataClassification,
*co_identifier,
*allowed,
*reason
);
if (*allowed == 0) {
# We were too impolite.
*message = *reason;
} else {
# There were actually no objections. Something else must
# have gone wrong.
# The *message set in the start of this rule is returned.
}
}
}
# \brief Modify a group.
#
# This is mostly a shortcut for setting single-value attributes on a group
# object. Allowed properties are: 'category', 'subcategory', 'description', 'expiration_date', and
# 'data_classification'.
#
# \param[in] groupName
# \param[in] property the property to change
# \param[in] value the new property value
# \param[out] status '0' on success, non-zero on failure
# \param[out] message a user friendly error message, may contain the reason why an action was disallowed
#
uuGroupModify(*groupName, *property, *value, *status, *message) {
*status = '1';
*message = "An internal error occurred.";
*kv.'.' = ".";
if (*value == "") {
# XXX This exact workaround exists in the `uuGroupAdd` rule as well.
# If you change this block, change it there too.
# Work around an iRODS bug that causes errors when changing metadata
# values to an empty string in specific situations.
# 'description' is currently the only property that can be set to empty
# by the user, and we handle that case here.
*value = ".";
# This dot must be treated specially (as an empty string) in query
# functions.
}
if (*property == "category") {
# We must pass the current category name such that the postproc rule
# for metaset can revoke read access from the current datamanager group
# in our category if it exists.
uuGroupGetCategory(*groupName, *category, *_);
*kv.'oldCategory' = *category;
}
*status = str(errorcode(msiSudoObjMetaSet(*groupName, "-u", *property, *value, "", *kv)));
if (*status == '0') {
*message = "";
} else {
uuGroupPolicyCanGroupModify(uuClientFullName, *groupName, *property, *value, *allowed, *reason);
if (*allowed == 0) {
*message = *reason;
}
}
}
# \brief Remove a group.
#
# \param[in] groupName
# \param[out] status '0' on success, non-zero on failure
# \param[out] message a user friendly error message, may contain the reason why an action was disallowed
#
uuGroupRemove(*groupName, *status, *message) {
*status = '1';
*message = "An internal error occurred.";
*status = str(errorcode(msiSudoGroupRemove(*groupName, "")));
if (*status == '0') {
*message = "";
} else {
uuGroupPolicyCanGroupRemove(uuClientFullName, *groupName, *allowed, *reason);
if (*allowed == 0) {
*message = *reason;
}
}
}
# \brief Modify a user.
#
# This is mostly a shortcut for setting single-value attributes on a user
# object.
#
# \param[in] userName
# \param[in] property the property to change
# \param[in] value the new property value
# \param[out] status zero on success, non-zero on failure
# \param[out] message a user friendly error message, may contain the reason why an action was disallowed
#
uuUserModify(*userName, *property, *value, *status, *message) {
*status = 1;
*message = "An internal error occurred.";
*kv.'.' = ".";
if (*value == "") {
# XXX This exact workaround exists in the `uuGroupAdd` rule as well.
# If you change this block, change it there too.
# Work around an iRODS bug that causes errors when changing metadata
# values to an empty string in specific situations.
# 'description' is currently the only property that can be set to empty
# by the user, and we handle that case here.
*value = ".";
# This dot must be treated specially (as an empty string) in query
# functions.
}
*status = errorcode(msiSudoObjMetaSet(*userName, "-u", *property, *value, "", *kv));
if (*status == 0) {
*message = "";
} else {
uuUserPolicyCanUserModify(uuClientFullName, *userName, *property, *allowed, *reason);
if (*allowed == 0) {
*message = *reason;
}
}
}
# \brief Remove user metadata.
#
# \param[in] userName
# \param[in] property the property to remove
# \param[out] status zero on success, non-zero on failure
# \param[out] message a user friendly error message, may contain the reason why an action was disallowed
#
uuUserMetaRemove(*userName, *property, *status, *message) {
*status = 1;
*message = "An internal error occurred.";
*status = errorcode(msiSudoObjMetaRemove(*userName, "-u", "wildcards", *property, "", "", ""));
if (*status == 0) {
*message = "";
} else {
uuUserPolicyCanUserModify(uuClientFullName, *userName, *property, *allowed, *reason);
if (*allowed == 0) {
*message = *reason;
}
}
}
# \brief Add a user to a group on behalf of another user.
#
# \param[in] groupName
# \param[in] user the user to add to the group
# \param[in] creatorUser the user who will add the new user
# \param[in] creatorZone the zone of the user who will add the new user
# \param[out] status zero on success, non-zero on failure
# \param[out] message a user friendly error message, may contain the reason why an action was disallowed
#
uuGroupUserAdd(*groupName, *user, *creatorUser, *creatorZone, *status, *message) {
*status = '1';
*message = "An internal error occurred.";
*fullNameActor = "$userNameClient#$rodsZoneClient";
# Check that the creator user exists
*fullNameCreator = "*creatorUser#*creatorZone";
*exists = ""
rule_user_exists(*fullNameCreator, *exists);
# If creator does not exist, exit
if (*exists != "true") {
succeed; # Return here (fail would ruin the status and error message).
}
uuGetUserAndZone(*user, *userName, *userZone);
*fullName = "*userName#*userZone";
rule_user_exists(*fullName, *exists);
# User does not exist, add user to iRODS first.
if (*exists != "true") {
*kv."forGroup" = *groupName;
*status = str(errorcode(msiSudoUserAdd(*fullName, "", "", "", *kv)));
if (*status != '0') {
uuGroupPolicyCanGroupUserAdd(uuClientFullName, *groupName, *fullName, *allowed, *reason);
if (*allowed == 0) {
*message = *reason;
}
succeed; # Return here (fail would ruin the status and error message).
}
# Provision external user.
*externalUser = "";
rule_group_check_external_user(*userName, *externalUser)
if (*externalUser == "1") {
# Confirm that the actor is allowed to perform this action (either admin or the actor is the same as the creator user)
uuGetUserType(*fullNameActor, *actorUserType);
if (*actorUserType == "rodsadmin" || *fullNameCreator == *fullNameActor) {
*http_code = ""
*message = ""
rule_group_provision_external_user(*userName, *creatorUser, *creatorZone, *http_code, *message);
if (*message != "") {
writeLine("serverLog", "[EXTERNAL USER] *message");
*status = *http_code;
succeed; # Return here (fail would ruin the status and error message).
}
writeLine("serverLog", "[EXTERNAL USER] User *userName added by $userNameClient on $rodsZoneClient on the behalf of *creatorUser on *creatorZone.");
}
else {
# Actor user is not allowed to do this action
writeLine("serverLog", "[EXTERNAL USER] Actor $userNameClient on $rodsZoneClient does not have sufficient permissions to create external user *userName");
succeed; # Return here (fail would ruin the status and error message).
}
}
}
# User exists, now add them to the group.
*status = str(errorcode(msiSudoGroupMemberAdd(*groupName, *fullName, "")));
if (*status == '0') {
*message = "";
} else {
uuGroupPolicyCanGroupUserAdd(uuClientFullName, *groupName, *fullName, *allowed, *reason);
if (*allowed == 0) {
*message = *reason;
}
}