Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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