dat.h 5.3 KB

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