dat.h 4.5 KB

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