source: gpfs_3.1_ker2.6.20/lpp/mmfs/samples/uidremap/mmuid2name @ 195

Last change on this file since 195 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 2.7 KB
Line 
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
14if ($#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];
23print STDERR "$domain $intent $nUids $nGids\n" if $debug;
24
25# Basic argument sanity checking
26if ( ($intent ne "credentials") && ($intent ne "stat") && ($intent ne "acl") )
27{
28  die("Invalid intent value: $intent\n");
29}
30
31if ($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
37for ($i = 0; $i < $nUids; $i++)
38{
39  $uid[$i] = <STDIN>;
40  chop($uid[$i]);
41  print(STDERR "uid: $uid[$i]\n") if $debug;
42}
43for ($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.
58for ($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
77if ($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'
86for ($i = 0; $i < $nGids; $i++)
87{
88  print "\n";
89}
Note: See TracBrowser for help on using the repository browser.