blob: 77f40d6610b372b73b582e908851a6e64e04e3ac [file] [log] [blame]
rsc2277c5d2004-03-21 04:33:13 +00001#ifndef __AUTH_H__
2#define __AUTH_H__ 1
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7/*
8#pragma src "/sys/src/libauth"
9#pragma lib "libauth.a"
10*/
rscbaf3dc22005-02-08 21:04:13 +000011AUTOLIB(auth)
rsc2277c5d2004-03-21 04:33:13 +000012
13/*
14 * Interface for typical callers.
15 */
16
17typedef struct AuthInfo AuthInfo;
18typedef struct Chalstate Chalstate;
19typedef struct Chapreply Chapreply;
20typedef struct MSchapreply MSchapreply;
21typedef struct UserPasswd UserPasswd;
22typedef struct AuthRpc AuthRpc;
23
rscbaf3dc22005-02-08 21:04:13 +000024struct CFid;
25
rsc2277c5d2004-03-21 04:33:13 +000026enum
27{
28 MAXCHLEN= 256, /* max challenge length */
29 MAXNAMELEN= 256, /* maximum name length */
30 MD5LEN= 16,
31
32 ARok = 0, /* rpc return values */
33 ARdone,
34 ARerror,
35 ARneedkey,
36 ARbadkey,
37 ARwritenext,
38 ARtoosmall,
39 ARtoobig,
40 ARrpcfailure,
41 ARphase,
42
rsccbeb0b22006-04-01 19:24:03 +000043 AuthRpcMax = 4096
rsc2277c5d2004-03-21 04:33:13 +000044};
45
46struct AuthRpc
47{
48 int afd;
rscbaf3dc22005-02-08 21:04:13 +000049 struct CFid *afid;
rsc2277c5d2004-03-21 04:33:13 +000050 char ibuf[AuthRpcMax];
51 char obuf[AuthRpcMax];
52 char *arg;
53 uint narg;
54};
55
56struct AuthInfo
57{
58 char *cuid; /* caller id */
59 char *suid; /* server id */
60 char *cap; /* capability (only valid on server side) */
61 int nsecret; /* length of secret */
62 uchar *secret; /* secret */
63};
64
65struct Chalstate
66{
67 char *user;
68 char chal[MAXCHLEN];
69 int nchal;
70 void *resp;
71 int nresp;
72
73/* for implementation only */
rsc2277c5d2004-03-21 04:33:13 +000074 AuthRpc *rpc; /* to factotum */
75 char userbuf[MAXNAMELEN]; /* temp space if needed */
76 int userinchal; /* user was sent to obtain challenge */
77};
78
79struct Chapreply /* for protocol "chap" */
80{
81 uchar id;
82 char resp[MD5LEN];
83};
84
85struct MSchapreply /* for protocol "mschap" */
86{
87 char LMresp[24]; /* Lan Manager response */
88 char NTresp[24]; /* NT response */
89};
90
91struct UserPasswd
92{
93 char *user;
94 char *passwd;
95};
96
97extern int newns(char*, char*);
98extern int addns(char*, char*);
99
100extern int noworld(char*);
101extern int amount(int, char*, int, char*);
102
103/* these two may get generalized away -rsc */
104extern int login(char*, char*, char*);
105extern int httpauth(char*, char*);
106
107typedef struct Attr Attr;
108enum {
109 AttrNameval, /* name=val -- when matching, must have name=val */
110 AttrQuery, /* name? -- when matching, must be present */
rsccbeb0b22006-04-01 19:24:03 +0000111 AttrDefault /* name:=val -- when matching, if present must match INTERNAL */
rsc2277c5d2004-03-21 04:33:13 +0000112};
113struct Attr
114{
115 int type;
116 Attr *next;
117 char *name;
118 char *val;
119};
120
121typedef int AuthGetkey(char*);
122
123int _attrfmt(Fmt*);
124Attr *_copyattr(Attr*);
125Attr *_delattr(Attr*, char*);
126Attr *_findattr(Attr*, char*);
127void _freeattr(Attr*);
128Attr *_mkattr(int, char*, char*, Attr*);
129Attr *_parseattr(char*);
130char *_strfindattr(Attr*, char*);
131/*
132#pragma varargck type "A" Attr*
133*/
134
135extern AuthInfo* fauth_proxy(int, AuthRpc *rpc, AuthGetkey *getkey, char *params);
136extern AuthInfo* auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...);
rscbaf3dc22005-02-08 21:04:13 +0000137extern AuthInfo* fsfauth_proxy(struct CFid*, AuthRpc *rpc, AuthGetkey *getkey, char *params);
138extern AuthInfo* fsauth_proxy(struct CFid*, AuthGetkey *getkey, char *fmt, ...);
rsc2277c5d2004-03-21 04:33:13 +0000139extern int auth_getkey(char*);
140extern int (*amount_getkey)(char*);
141extern void auth_freeAI(AuthInfo *ai);
142extern int auth_chuid(AuthInfo *ai, char *ns);
143extern Chalstate *auth_challenge(char*, ...);
144extern AuthInfo* auth_response(Chalstate*);
145extern int auth_respond(void*, uint, char*, uint, void*, uint, AuthGetkey *getkey, char*, ...);
146extern void auth_freechal(Chalstate*);
147extern AuthInfo* auth_userpasswd(char *user, char *passwd);
148extern UserPasswd* auth_getuserpasswd(AuthGetkey *getkey, char*, ...);
149extern AuthInfo* auth_getinfo(AuthRpc *rpc);
rscbaf3dc22005-02-08 21:04:13 +0000150extern AuthRpc* auth_allocrpc(void);
rsc2277c5d2004-03-21 04:33:13 +0000151extern Attr* auth_attr(AuthRpc *rpc);
152extern void auth_freerpc(AuthRpc *rpc);
153extern uint auth_rpc(AuthRpc *rpc, char *verb, void *a, int n);
154extern int auth_wep(char*, char*, ...);
rscce2a3782005-02-10 16:08:16 +0000155
156extern struct CFsys* fsamount(int fd, char *aname);
157extern struct CFsys* nsamount(char *name, char *aname);
158
159
rsc2277c5d2004-03-21 04:33:13 +0000160/*
161#pragma varargck argpos auth_proxy 3
162#pragma varargck argpos auth_challenge 1
163#pragma varargck argpos auth_respond 3
164#pragma varargck argpos auth_getuserpasswd 2
165*/
166#ifdef __cplusplus
167}
168#endif
169#endif