1 #include "all.h"
2
3 void mapinit(char*, char*);
4
5 int debug;
6 int rpcdebug;
7 int style = 'u';
8 Biobuf *in;
9 Unixid *ids;
10 Unixid **pids;
11 Unixidmap *mp;
12
13 void
main(int argc,char ** argv)14 main(int argc, char **argv)
15 {
16 int id, arc; char *arv[4];
17 char *l, *name;
18
19 chatty = 1;
20 ARGBEGIN{
21 case '9':
22 case 'u':
23 style = ARGC();
24 break;
25 case 'D':
26 ++debug;
27 break;
28 }ARGEND
29 if(argc <= 0){
30 ids = readunixids("/fd/0", style);
31 if(ids)
32 idprint(1, ids);
33 exits(ids ? 0 : "readunixids");
34 }
35 mapinit(argv[0], 0);
36 in = Bopen("/fd/0", OREAD);
37 while(l = Brdline(in, '\n')){ /* assign = */
38 l[Blinelen(in)-1] = 0;
39 arc = strparse(l, nelem(arv), arv);
40 if(arc <= 0)
41 continue;
42 switch(arv[0][0]){
43 case 'r':
44 if(arc < 2)
45 continue;
46 mapinit(arv[1], arv[2]);
47 break;
48 case 'i':
49 if(arc < 2)
50 continue;
51 id = strtol(arv[1], 0, 10);
52 name = id2name(pids, id);
53 print("%d -> %s\n", id, name);
54 break;
55 case 'n':
56 if(arc < 2)
57 continue;
58 name = arv[1];
59 id = name2id(pids, name);
60 print("%s -> %d\n", name, id);
61 break;
62 case 'p':
63 print("server=%s, client=%s\n", mp->server, mp->client);
64 break;
65 case 'P':
66 idprint(1, *pids);
67 break;
68 case 'u':
69 pids = &mp->u.ids;
70 print("users...\n");
71 break;
72 case 'g':
73 pids = &mp->g.ids;
74 print("groups...\n");
75 break;
76 }
77 }
78 exits(0);
79 }
80
81 void
mapinit(char * file,char * client)82 mapinit(char *file, char *client)
83 {
84 if(file){
85 print("reading %s...\n", file);
86 if(readunixidmaps(file) < 0)
87 exits("readunixidmaps");
88 if(!client)
89 client = "nslocum.research.bell-labs.com";
90 }
91 print("client = %s...\n", client);
92 mp = pair2idmap("bootes", client, 0);
93 if(mp == 0){
94 fprint(2, "%s: pair2idmap failed\n", argv0);
95 exits("pair2idmap");
96 }
97 pids = &mp->u.ids;
98 print("[users...]\n");
99 }
100