Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_init / userUtils.pl
1 #\r
2 # Copyright (c) 2002-2003\r
3 #      The President and Fellows of Harvard College.\r
4 #\r
5 # Redistribution and use in source and binary forms, with or without\r
6 # modification, are permitted provided that the following conditions\r
7 # are met:\r
8 # 1. Redistributions of source code must retain the above copyright\r
9 #    notice, this list of conditions and the following disclaimer.\r
10 # 2. Redistributions in binary form must reproduce the above copyright\r
11 #    notice, this list of conditions and the following disclaimer in the\r
12 #    documentation and/or other materials provided with the distribution.\r
13 # 3. Neither the name of the University nor the names of its contributors\r
14 #    may be used to endorse or promote products derived from this software\r
15 #    without specific prior written permission.\r
16 #\r
17 # THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND\r
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
20 # ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE\r
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
27 # SUCH DAMAGE.\r
28 #\r
29 # $Id: userUtils.pl,v 1.5 2003/07/26 20:52:04 ellard Exp $\r
30 #\r
31 # utils.pl - deal with details like turning login names into uids.\r
32 #\r
33 \r
34 sub logins2uids {\r
35         my ($str) = @_;\r
36 \r
37         my @uids = ();\r
38         my @logins = split (/,/, $str);\r
39 \r
40         my $j = 0;\r
41         for (my $i = 0; $i < @logins; $i++) {\r
42                 if ($logins[$i] =~ /^[0-9]/) {\r
43                         $uids[$j++] = $logins[$i];\r
44                 }\r
45                 else {\r
46                         my ($login, $pw, $uid, $gid) = getpwnam ($logins[$i]);\r
47                         if (defined $uid) {\r
48                                 $uids[$j++] = $uid;\r
49                         }\r
50                         else {\r
51                                 # &&& Warning or error?\r
52                                 print STDERR "WARNING: Unrecognized login ($logins[$i])\n";\r
53                                 $uids[$j++] = $logins[$i];\r
54                         }\r
55                 }\r
56         }\r
57 \r
58         return (@uids);\r
59 }\r
60 \r
61 sub groups2gids {\r
62         my ($str) = @_;\r
63 \r
64         my @gids = ();\r
65         my @groups = split (/,/, $str);\r
66 \r
67         for (my $i = 0; $i < @groups; $i++) {\r
68                 if ($groups[$i] =~ /^[0-9]/) {\r
69                         $gids[$j++] = $groups[$i];\r
70                 }\r
71                 else {\r
72                         my $gid = getgrnam ($groups[$i]);\r
73                         if (defined $gid) {\r
74                                 $gids[$j++] = $gid;\r
75                         }\r
76                         else {\r
77                                 # &&& Warning or error?\r
78                                 print STDERR "WARNING: Unrecognized group ($logins[$i])\n";\r
79                                 $gids[$j++] = $groups[$i];\r
80                         }\r
81                 }\r
82         }\r
83 \r
84         return (@gids);\r
85 }\r
86 \r
87 1;\r