nametest.c 2.1 KB

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