| 1 | #!/usr/bin/perl |
|---|
| 2 | # |
|---|
| 3 | # This is a sample implementation of a UID/GID GPFS remapping helper |
|---|
| 4 | # application pair, provided for testing and illustrative purposes. It uses |
|---|
| 5 | # the Full Name (a.k.a. gecos) field in /etc/passwd as the globally unique user |
|---|
| 6 | # name. No name-based GID remapping is done in this implementation. When |
|---|
| 7 | # remapping for the purposes of credentials checking (intent is 'credentials'), |
|---|
| 8 | # we do remapping for the UID based on the symbolic name, and replace the |
|---|
| 9 | # entire list of GIDs with the GIDs of the user on the home cluster. |
|---|
| 10 | # |
|---|
| 11 | |
|---|
| 12 | $debug = 0; |
|---|
| 13 | |
|---|
| 14 | if ($#ARGV != 3) |
|---|
| 15 | { |
|---|
| 16 | die("Usage: mmuid2name domain intent nUids nGids\n"); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | $domain = $ARGV[0]; |
|---|
| 20 | $intent = $ARGV[1]; |
|---|
| 21 | $nUids = $ARGV[2]; |
|---|
| 22 | $nGids = $ARGV[3]; |
|---|
| 23 | print STDERR "$domain $intent $nUids $nGids\n" if $debug; |
|---|
| 24 | |
|---|
| 25 | # Basic argument sanity checking |
|---|
| 26 | if ( ($intent ne "credentials") && ($intent ne "stat") && ($intent ne "acl") ) |
|---|
| 27 | { |
|---|
| 28 | die("Invalid intent value: $intent\n"); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | if ($nUids == 0 && ($intent eq "credentials")) |
|---|
| 32 | { |
|---|
| 33 | die("The number of UIDs to be remapped cannot be zero\n"); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | # Read the list of UIDs and GIDs |
|---|
| 37 | for ($i = 0; $i < $nUids; $i++) |
|---|
| 38 | { |
|---|
| 39 | $uid[$i] = <STDIN>; |
|---|
| 40 | chop($uid[$i]); |
|---|
| 41 | print(STDERR "uid: $uid[$i]\n") if $debug; |
|---|
| 42 | } |
|---|
| 43 | for ($i = 0; $i < $nGids; $i++) |
|---|
| 44 | { |
|---|
| 45 | $gid[$i] = <STDIN>; |
|---|
| 46 | chop($gid[$i]); |
|---|
| 47 | print (STDERR "gid: $gid[$i]\n") if $debug; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | # Go through the list of uids, and for those that are known, output the |
|---|
| 51 | # full name (aka gecos field). For those uids that are not found, output |
|---|
| 52 | # "UNKNOWN USER" string. The choice of string to denote an unknown user is |
|---|
| 53 | # arbitrary, anything will do as long as both mmuid2name and mmname2uid use |
|---|
| 54 | # the same convention. An empty string would a logical choice for a real-life |
|---|
| 55 | # situation, since it minimizes the size of the messages passed between nodes |
|---|
| 56 | # for UID remapping purposes. However, in this example a more definitive |
|---|
| 57 | # string would work better since /etc/passwd often has empty gecos fields. |
|---|
| 58 | for ($i = 0; $i < $nUids; $i++) |
|---|
| 59 | { |
|---|
| 60 | @f = getpwuid($uid[$i]); |
|---|
| 61 | if ($#f != -1) |
|---|
| 62 | { |
|---|
| 63 | print (STDERR "$f[6]\n") if $debug; |
|---|
| 64 | print ("$f[6]\n"); |
|---|
| 65 | } |
|---|
| 66 | else |
|---|
| 67 | { |
|---|
| 68 | print (STDERR "UNKNOWN USER\n") if $debug; |
|---|
| 69 | print ("UNKNOWN USER\n"); |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | # In this implementation, for the purposes of credentials checking we only remap |
|---|
| 74 | # uids but not gids. We don't need to output anything at all for gids, so |
|---|
| 75 | # we quit here. |
|---|
| 76 | |
|---|
| 77 | if ($intent eq "credentials") |
|---|
| 78 | { |
|---|
| 79 | exit(0); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | # Since we don't try to do remapping for gids for stat, there's no additional |
|---|
| 83 | # work. However, we still need to output something (an empty line in our case) |
|---|
| 84 | # because the convention is to generate the stated number of output lines for |
|---|
| 85 | # intents other than 'credentials' |
|---|
| 86 | for ($i = 0; $i < $nGids; $i++) |
|---|
| 87 | { |
|---|
| 88 | print "\n"; |
|---|
| 89 | } |
|---|