Blob


1 #ifndef __AUTH_H__
2 #define __AUTH_H__ 1
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 /*
8 #pragma src "/sys/src/libauth"
9 #pragma lib "libauth.a"
10 */
12 /*
13 * Interface for typical callers.
14 */
16 typedef struct AuthInfo AuthInfo;
17 typedef struct Chalstate Chalstate;
18 typedef struct Chapreply Chapreply;
19 typedef struct MSchapreply MSchapreply;
20 typedef struct UserPasswd UserPasswd;
21 typedef struct AuthRpc AuthRpc;
23 enum
24 {
25 MAXCHLEN= 256, /* max challenge length */
26 MAXNAMELEN= 256, /* maximum name length */
27 MD5LEN= 16,
29 ARok = 0, /* rpc return values */
30 ARdone,
31 ARerror,
32 ARneedkey,
33 ARbadkey,
34 ARwritenext,
35 ARtoosmall,
36 ARtoobig,
37 ARrpcfailure,
38 ARphase,
40 AuthRpcMax = 4096,
41 };
43 struct AuthRpc
44 {
45 int afd;
46 char ibuf[AuthRpcMax];
47 char obuf[AuthRpcMax];
48 char *arg;
49 uint narg;
50 };
52 struct AuthInfo
53 {
54 char *cuid; /* caller id */
55 char *suid; /* server id */
56 char *cap; /* capability (only valid on server side) */
57 int nsecret; /* length of secret */
58 uchar *secret; /* secret */
59 };
61 struct Chalstate
62 {
63 char *user;
64 char chal[MAXCHLEN];
65 int nchal;
66 void *resp;
67 int nresp;
69 /* for implementation only */
70 int afd; /* to factotum */
71 AuthRpc *rpc; /* to factotum */
72 char userbuf[MAXNAMELEN]; /* temp space if needed */
73 int userinchal; /* user was sent to obtain challenge */
74 };
76 struct Chapreply /* for protocol "chap" */
77 {
78 uchar id;
79 char resp[MD5LEN];
80 };
82 struct MSchapreply /* for protocol "mschap" */
83 {
84 char LMresp[24]; /* Lan Manager response */
85 char NTresp[24]; /* NT response */
86 };
88 struct UserPasswd
89 {
90 char *user;
91 char *passwd;
92 };
94 extern int newns(char*, char*);
95 extern int addns(char*, char*);
97 extern int noworld(char*);
98 extern int amount(int, char*, int, char*);
100 /* these two may get generalized away -rsc */
101 extern int login(char*, char*, char*);
102 extern int httpauth(char*, char*);
104 typedef struct Attr Attr;
105 enum {
106 AttrNameval, /* name=val -- when matching, must have name=val */
107 AttrQuery, /* name? -- when matching, must be present */
108 AttrDefault, /* name:=val -- when matching, if present must match INTERNAL */
109 };
110 struct Attr
112 int type;
113 Attr *next;
114 char *name;
115 char *val;
116 };
118 typedef int AuthGetkey(char*);
120 int _attrfmt(Fmt*);
121 Attr *_copyattr(Attr*);
122 Attr *_delattr(Attr*, char*);
123 Attr *_findattr(Attr*, char*);
124 void _freeattr(Attr*);
125 Attr *_mkattr(int, char*, char*, Attr*);
126 Attr *_parseattr(char*);
127 char *_strfindattr(Attr*, char*);
128 /*
129 #pragma varargck type "A" Attr*
130 */
132 extern AuthInfo* fauth_proxy(int, AuthRpc *rpc, AuthGetkey *getkey, char *params);
133 extern AuthInfo* auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...);
134 extern int auth_getkey(char*);
135 extern int (*amount_getkey)(char*);
136 extern void auth_freeAI(AuthInfo *ai);
137 extern int auth_chuid(AuthInfo *ai, char *ns);
138 extern Chalstate *auth_challenge(char*, ...);
139 extern AuthInfo* auth_response(Chalstate*);
140 extern int auth_respond(void*, uint, char*, uint, void*, uint, AuthGetkey *getkey, char*, ...);
141 extern void auth_freechal(Chalstate*);
142 extern AuthInfo* auth_userpasswd(char *user, char *passwd);
143 extern UserPasswd* auth_getuserpasswd(AuthGetkey *getkey, char*, ...);
144 extern AuthInfo* auth_getinfo(AuthRpc *rpc);
145 extern AuthRpc* auth_allocrpc(int afd);
146 extern Attr* auth_attr(AuthRpc *rpc);
147 extern void auth_freerpc(AuthRpc *rpc);
148 extern uint auth_rpc(AuthRpc *rpc, char *verb, void *a, int n);
149 extern int auth_wep(char*, char*, ...);
150 /*
151 #pragma varargck argpos auth_proxy 3
152 #pragma varargck argpos auth_challenge 1
153 #pragma varargck argpos auth_respond 3
154 #pragma varargck argpos auth_getuserpasswd 2
155 */
156 #ifdef __cplusplus
158 #endif
159 #endif