dat.h 4.7 KB

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