Import TBBT (NFS trace replay).
[bluesky.git] / TBBT / trace_init / userUtils.pl
diff --git a/TBBT/trace_init/userUtils.pl b/TBBT/trace_init/userUtils.pl
new file mode 100755 (executable)
index 0000000..4019d5d
--- /dev/null
@@ -0,0 +1,87 @@
+#\r
+# Copyright (c) 2002-2003\r
+#      The President and Fellows of Harvard College.\r
+#\r
+# Redistribution and use in source and binary forms, with or without\r
+# modification, are permitted provided that the following conditions\r
+# are met:\r
+# 1. Redistributions of source code must retain the above copyright\r
+#    notice, this list of conditions and the following disclaimer.\r
+# 2. Redistributions in binary form must reproduce the above copyright\r
+#    notice, this list of conditions and the following disclaimer in the\r
+#    documentation and/or other materials provided with the distribution.\r
+# 3. Neither the name of the University nor the names of its contributors\r
+#    may be used to endorse or promote products derived from this software\r
+#    without specific prior written permission.\r
+#\r
+# THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND\r
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE\r
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+# SUCH DAMAGE.\r
+#\r
+# $Id: userUtils.pl,v 1.5 2003/07/26 20:52:04 ellard Exp $\r
+#\r
+# utils.pl - deal with details like turning login names into uids.\r
+#\r
+\r
+sub logins2uids {\r
+       my ($str) = @_;\r
+\r
+       my @uids = ();\r
+       my @logins = split (/,/, $str);\r
+\r
+       my $j = 0;\r
+       for (my $i = 0; $i < @logins; $i++) {\r
+               if ($logins[$i] =~ /^[0-9]/) {\r
+                       $uids[$j++] = $logins[$i];\r
+               }\r
+               else {\r
+                       my ($login, $pw, $uid, $gid) = getpwnam ($logins[$i]);\r
+                       if (defined $uid) {\r
+                               $uids[$j++] = $uid;\r
+                       }\r
+                       else {\r
+                               # &&& Warning or error?\r
+                               print STDERR "WARNING: Unrecognized login ($logins[$i])\n";\r
+                               $uids[$j++] = $logins[$i];\r
+                       }\r
+               }\r
+       }\r
+\r
+       return (@uids);\r
+}\r
+\r
+sub groups2gids {\r
+       my ($str) = @_;\r
+\r
+       my @gids = ();\r
+       my @groups = split (/,/, $str);\r
+\r
+       for (my $i = 0; $i < @groups; $i++) {\r
+               if ($groups[$i] =~ /^[0-9]/) {\r
+                       $gids[$j++] = $groups[$i];\r
+               }\r
+               else {\r
+                       my $gid = getgrnam ($groups[$i]);\r
+                       if (defined $gid) {\r
+                               $gids[$j++] = $gid;\r
+                       }\r
+                       else {\r
+                               # &&& Warning or error?\r
+                               print STDERR "WARNING: Unrecognized group ($logins[$i])\n";\r
+                               $gids[$j++] = $groups[$i];\r
+                       }\r
+               }\r
+       }\r
+\r
+       return (@gids);\r
+}\r
+\r
+1;\r