dat.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 <u.h>
  10. #include <libc.h>
  11. #include <auth.h>
  12. #include <authsrv.h>
  13. #include <mp.h>
  14. #include <libsec.h>
  15. #include <String.h>
  16. #include <thread.h> /* only for 9p.h */
  17. #include <fcall.h>
  18. #include <9p.h>
  19. enum
  20. {
  21. Maxname = 128,
  22. Maxrpc = 4096,
  23. /* common protocol phases; proto-specific phases start at 0 */
  24. Notstarted = -3,
  25. Broken = -2,
  26. Established = -1,
  27. /* rpc read/write return values */
  28. RpcFailure = 0,
  29. RpcNeedkey,
  30. RpcOk,
  31. RpcErrstr,
  32. RpcToosmall,
  33. RpcPhase,
  34. RpcConfirm,
  35. };
  36. typedef struct Domain Domain;
  37. typedef struct Fsstate Fsstate;
  38. typedef struct Key Key;
  39. typedef struct Keyinfo Keyinfo;
  40. typedef struct Keyring Keyring;
  41. typedef struct Logbuf Logbuf;
  42. typedef struct Proto Proto;
  43. typedef struct State State;
  44. struct Fsstate
  45. {
  46. char *sysuser; /* user according to system */
  47. /* keylist, protolist */
  48. int listoff;
  49. /* per-rpc transient information */
  50. int pending;
  51. struct {
  52. char *arg, buf[Maxrpc], *verb;
  53. int iverb, narg, nbuf, nwant;
  54. } rpc;
  55. /* persistent (cross-rpc) information */
  56. char err[ERRMAX];
  57. char keyinfo[3*Maxname]; /* key request */
  58. char **phasename;
  59. int haveai, maxphase, phase, seqnum, started;
  60. Attr *attr;
  61. AuthInfo ai;
  62. Proto *proto;
  63. State *ps;
  64. struct { /* pending or finished key confirmations */
  65. Key *key;
  66. int canuse;
  67. uint32_t tag;
  68. } *conf;
  69. int nconf;
  70. };
  71. struct Key
  72. {
  73. int ref;
  74. Attr *attr;
  75. Attr *privattr; /* private attributes, like *data */
  76. Proto *proto;
  77. void *priv; /* protocol-specific; a parsed key, perhaps */
  78. uint32_t successes;
  79. };
  80. struct Keyinfo /* for findkey */
  81. {
  82. Fsstate *fss;
  83. char *user;
  84. int noconf;
  85. int skip;
  86. int usedisabled;
  87. Attr *attr;
  88. };
  89. struct Keyring
  90. {
  91. Key **key;
  92. int nkey;
  93. };
  94. struct Logbuf
  95. {
  96. Req *wait;
  97. Req **waitlast;
  98. int rp;
  99. int wp;
  100. char *msg[128];
  101. };
  102. struct Proto
  103. {
  104. char *name;
  105. int (*init)(Proto*, Fsstate*);
  106. int (*addkey)(Key*, int);
  107. void (*closekey)(Key*);
  108. int (*write)(Fsstate*, void*, uint);
  109. int (*read)(Fsstate*, void*, uint*);
  110. void (*close)(Fsstate*);
  111. char *keyprompt;
  112. };
  113. extern char *invoker;
  114. extern char *owner;
  115. extern char *authdom;
  116. extern char Easproto[];
  117. extern char Ebadarg[];
  118. extern char Ebadkey[];
  119. extern char Enegotiation[];
  120. extern char Etoolarge[];
  121. /* confirm.c */
  122. void confirmread(Req*);
  123. void confirmflush(Req*);
  124. int confirmwrite(char*);
  125. void confirmqueue(Req*, Fsstate*);
  126. void needkeyread(Req*);
  127. void needkeyflush(Req*);
  128. int needkeywrite(char*);
  129. int needkeyqueue(Req*, Fsstate*);
  130. /* fs.c */
  131. extern int askforkeys;
  132. extern char *authaddr;
  133. extern int *confirminuse;
  134. extern int debug;
  135. extern int gflag;
  136. extern int kflag;
  137. extern int *needkeyinuse;
  138. extern int sflag;
  139. extern int uflag;
  140. extern char *mtpt;
  141. extern char *service;
  142. extern Proto *prototab[];
  143. extern Keyring *ring;
  144. /* log.c */
  145. void flog(char*, ...);
  146. void logread(Req*);
  147. void logflush(Req*);
  148. void logbufflush(Logbuf*, Req*);
  149. void logbufread(Logbuf*, Req*);
  150. void logbufproc(Logbuf*);
  151. void logbufappend(Logbuf*, char*);
  152. void needkeyread(Req*);
  153. void needkeyflush(Req*);
  154. int needkeywrite(char*);
  155. int needkeyqueue(Req*, Fsstate*);
  156. /* rpc.c */
  157. int ctlwrite(char*, int);
  158. void rpcrdwrlog(Fsstate*, char*, uint, int, int);
  159. void rpcstartlog(Attr*, Fsstate*, int);
  160. void rpcread(Req*);
  161. void rpcwrite(Req*);
  162. /* secstore.c */
  163. int havesecstore(void);
  164. int secstorefetch(char*);
  165. /* util.c */
  166. #define emalloc emalloc9p
  167. #define estrdup estrdup9p
  168. #define erealloc erealloc9p
  169. int _authdial(char*, char*);
  170. void askuser(char*);
  171. int attrnamefmt(Fmt *fmt);
  172. int canusekey(Fsstate*, Key*);
  173. void closekey(Key*);
  174. unsigned char *convAI2M(AuthInfo*, unsigned char*, int);
  175. void disablekey(Key*);
  176. char *estrappend(char*, char*, ...);
  177. int failure(Fsstate*, char*, ...);
  178. Keyinfo* mkkeyinfo(Keyinfo*, Fsstate*, Attr*);
  179. int findkey(Key**, Keyinfo*, char*, ...);
  180. int findp9authkey(Key**, Fsstate*);
  181. Proto *findproto(char*);
  182. char *getnvramkey(int, char**);
  183. void initcap(void);
  184. int isclient(char*);
  185. int matchattr(Attr*, Attr*, Attr*);
  186. void memrandom(void*, int);
  187. char *mkcap(char*, char*);
  188. int phaseerror(Fsstate*, char*);
  189. char *phasename(Fsstate*, int, char*);
  190. void promptforhostowner(void);
  191. char *readcons(char*, char*, int);
  192. int replacekey(Key*, int before);
  193. char *safecpy(char*, char*, int);
  194. int secdial(void);
  195. Attr *setattr(Attr*, char*, ...);
  196. Attr *setattrs(Attr*, Attr*);
  197. void sethostowner(void);
  198. void setmalloctaghere(void*);
  199. int smatch(char*, char*);
  200. Attr *sortattr(Attr*);
  201. int toosmall(Fsstate*, uint);
  202. void writehostowner(char*);
  203. /* protocols */
  204. extern Proto apop, cram; /* apop.c */
  205. extern Proto p9any, p9sk1, p9sk2; /* p9sk.c */
  206. extern Proto chap, mschap; /* chap.c */
  207. extern Proto p9cr, vnc; /* p9cr.c */
  208. extern Proto pass; /* pass.c */
  209. extern Proto rsa; /* rsa.c */
  210. extern Proto wep; /* wep.c */
  211. /* extern Proto srs;*/ /* srs.c */
  212. extern Proto httpdigest; /* httpdigest.c */