nametest.c 1.7 KB

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