pcnfsd.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include "all.h"
  2. static void pcinit(int, char**);
  3. static int pcnull(int, Rpccall*, Rpccall*);
  4. static int pcinfo(int, Rpccall*, Rpccall*);
  5. static int pcauth(int, Rpccall*, Rpccall*);
  6. static int pc1auth(int, Rpccall*, Rpccall*);
  7. static int pcfacilities[15];
  8. static char no_comment[] = "Trust me.";
  9. static char pc_vers[] = "@(#)pcnfsd_v2.c 1.6 - rpc.pcnfsd V2.0 (c) 1994 P9, GmbH";
  10. static char pc_home[] = "merrimack:/";
  11. static Procmap pcproc[] = { /* pcnfsd v2 */
  12. 0, pcnull,
  13. 1, pcinfo,
  14. 13, pcauth,
  15. 0, 0
  16. };
  17. static Procmap pc1proc[] = { /* pc-nfsd v1 */
  18. 0, pcnull,
  19. 1, pc1auth,
  20. 0, 0
  21. };
  22. int myport = 1111;
  23. Progmap progmap[] = {
  24. 150001, 2, pcinit, pcproc,
  25. 150001, 1, 0, pc1proc,
  26. 0, 0, 0,
  27. };
  28. void
  29. main(int argc, char *argv[])
  30. {
  31. server(argc, argv, myport, progmap);
  32. }
  33. static void
  34. pcinit(int argc, char **argv)
  35. {
  36. Procmap *p;
  37. int i;
  38. char *config = "config";
  39. ARGBEGIN{
  40. case 'c':
  41. config = ARGF();
  42. break;
  43. default:
  44. if(argopt(ARGC()) < 0)
  45. sysfatal("usage: %s %s [-c config]", argv0, commonopts);
  46. break;
  47. }ARGEND;
  48. clog("pc init\n");
  49. for(i=0; i<nelem(pcfacilities); i++)
  50. pcfacilities[i] = -1;
  51. for(p=pcproc; p->procp; p++)
  52. pcfacilities[p->procno] = 100;
  53. readunixidmaps(config);
  54. }
  55. static int
  56. pcnull(int n, Rpccall *cmd, Rpccall *reply)
  57. {
  58. USED(n, cmd, reply);
  59. return 0;
  60. }
  61. static void
  62. scramble(String *x)
  63. {
  64. int i;
  65. for(i=0; i<x->n; i++)
  66. x->s[i] = (x->s[i] ^ 0x5b) & 0x7f;
  67. }
  68. static int
  69. pcinfo(int n, Rpccall *cmd, Rpccall *reply)
  70. {
  71. uchar *argptr = cmd->args;
  72. uchar *dataptr = reply->results;
  73. String vers, cm;
  74. int i;
  75. chat("host=%I, port=%ld: pcinfo...",
  76. cmd->host, cmd->port);
  77. if(n <= 16)
  78. return garbage(reply, "count too small");
  79. argptr += string2S(argptr, &vers);
  80. argptr += string2S(argptr, &cm);
  81. if(argptr != &((uchar *)cmd->args)[n])
  82. return garbage(reply, "bad count");
  83. chat("\"%.*s\",\"%.*s\"\n", utfnlen(vers.s, vers.n), vers.s, utfnlen(cm.s, cm.n), cm.s);
  84. PLONG(sizeof(pc_vers)-1);
  85. PPTR(pc_vers, sizeof(pc_vers)-1);
  86. PLONG(sizeof(no_comment)-1);
  87. PPTR(no_comment, sizeof(no_comment)-1);
  88. PLONG(nelem(pcfacilities));
  89. for(i=0; i<nelem(pcfacilities); i++)
  90. PLONG(pcfacilities[i]);
  91. return dataptr - (uchar *)reply->results;
  92. }
  93. static int
  94. pc1auth(int n, Rpccall *cmd, Rpccall *reply)
  95. {
  96. uchar *argptr = cmd->args;
  97. uchar *dataptr = reply->results;
  98. String id, pw;
  99. Unixidmap *m;
  100. int uid;
  101. chat("host=%I, port=%ld: pcauth...",
  102. cmd->host, cmd->port);
  103. if(n <= 8)
  104. return garbage(reply, "count too small");
  105. argptr += string2S(argptr, &id);
  106. argptr += string2S(argptr, &pw);
  107. if(argptr != &((uchar*)cmd->args)[n])
  108. return garbage(reply, "bad count");
  109. scramble(&id);
  110. scramble(&pw);
  111. m = pair2idmap("pcnfsd", cmd->host);
  112. uid = -1;
  113. if(m)
  114. uid = name2id(&m->u.ids, id.s);
  115. if(uid < 0)
  116. uid = 1;
  117. chat("\"%.*s\",\"%.*s\" uid=%d\n", utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, uid);
  118. PLONG(0); /* status */
  119. PLONG(uid); /* uid */
  120. PLONG(uid); /* gid */
  121. return dataptr - (uchar*)reply->results;
  122. }
  123. static int
  124. pcauth(int n, Rpccall *cmd, Rpccall *reply)
  125. {
  126. uchar *argptr = cmd->args;
  127. uchar *dataptr = reply->results;
  128. String sys, id, pw, cm;
  129. Unixidmap *m;
  130. int uid;
  131. chat("host=%I, port=%ld: pcauth...",
  132. cmd->host, cmd->port);
  133. if(n <= 16)
  134. return garbage(reply, "count too small");
  135. argptr += string2S(argptr, &sys);
  136. argptr += string2S(argptr, &id);
  137. argptr += string2S(argptr, &pw);
  138. argptr += string2S(argptr, &cm);
  139. if(argptr != &((uchar *)cmd->args)[n])
  140. return garbage(reply, "bad count");
  141. scramble(&id);
  142. scramble(&pw);
  143. m = pair2idmap("pcnfsd", cmd->host);
  144. uid = -1;
  145. if(m)
  146. uid = name2id(&m->u.ids, id.s);
  147. if(uid < 0)
  148. uid = 1;
  149. chat("\"%.*s\",\"%.*s\",\"%.*s\",\"%.*s\"\n", utfnlen(sys.s, sys.n), sys.s,
  150. utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, utfnlen(cm.s, cm.n), cm.s);
  151. PLONG(0); /* status - OK */
  152. PLONG(uid);
  153. PLONG(uid); /* gid */
  154. PLONG(0); /* ngids */
  155. PLONG(sizeof(pc_home)-1);
  156. PPTR(pc_home, sizeof(pc_home)-1);
  157. PLONG(0); /* umask */
  158. PLONG(sizeof(no_comment)-1);
  159. PPTR(no_comment, sizeof(no_comment)-1);
  160. return dataptr - (uchar *)reply->results;
  161. }