]> git.lizzy.rs Git - plan9front.git/blob - sys/include/ape/auth.h
Handle NaN and Inf edge cases as specified by posix, instead of barfing.
[plan9front.git] / sys / include / ape / auth.h
1 #ifndef _PLAN9_SOURCE
2   This header file is an extension to ANSI/POSIX
3 #endif
4
5 #ifndef __AUTH_H_
6 #define __AUTH_H_
7
8 #pragma src     "/sys/src/ape/lib/auth"
9 #pragma lib     "/$M/lib/ape/libauth.a"
10
11 #include <u.h>
12 #include <fmt.h>
13
14 /*
15  * Interface for typical callers.
16  */
17
18 typedef struct  AuthInfo        AuthInfo;
19 typedef struct  Chalstate       Chalstate;
20 typedef struct  Chapreply       Chapreply;
21 typedef struct  MSchapreply     MSchapreply;
22 typedef struct  UserPasswd      UserPasswd;
23 typedef struct  AuthRpc         AuthRpc;
24
25 enum
26 {
27         MAXCHLEN=       256,            /* max challenge length */
28         MAXNAMELEN=     256,            /* maximum name length */
29         MD5LEN=         16,
30
31         ARok = 0,                       /* rpc return values */
32         ARdone,
33         ARerror,
34         ARneedkey,
35         ARbadkey,
36         ARwritenext,
37         ARtoosmall,
38         ARtoobig,
39         ARrpcfailure,
40         ARphase,
41
42         AuthRpcMax = 4096,
43 };
44
45 struct AuthRpc
46 {
47         int afd;
48         char ibuf[AuthRpcMax+1];        /* +1 for NUL in auth_rpc.c */
49         char obuf[AuthRpcMax];
50         char *arg;
51         uint narg;
52 };
53
54 struct AuthInfo
55 {
56         char    *cuid;          /* caller id */
57         char    *suid;          /* server id */
58         char    *cap;           /* capability (only valid on server side) */
59         int     nsecret;        /* length of secret */
60         uchar   *secret;        /* secret */
61 };
62
63 struct Chalstate
64 {
65         char    *user;
66         char    *dom;
67         char    chal[MAXCHLEN];
68         int     nchal;
69         void    *resp;
70         int     nresp;
71
72 /* for implementation only */
73         int     afd;                    /* to factotum */
74         AuthRpc *rpc;                   /* to factotum */
75         char    userbuf[MAXNAMELEN];    /* temp space if needed */
76         int     userinchal;             /* user was sent to obtain challenge */
77 };
78
79 struct  Chapreply               /* for protocol "chap" */
80 {
81         uchar   id;
82         char    resp[MD5LEN];
83 };
84
85 struct  MSchapreply             /* for protocol "mschap" and "ntlm" */
86 {
87         char    LMresp[24];             /* Lan Manager response */
88         char    NTresp[24];             /* NT response */
89 };
90
91 struct  UserPasswd
92 {
93         char    *user;
94         char    *passwd;
95 };
96
97 extern  int     newns(char*, char*);
98 extern  int     addns(char*, char*);
99
100 extern  int     noworld(char*);
101 extern  int     amount(int, char*, int, char*);
102
103 extern  int     login(char*, char*, char*);
104
105 typedef struct Attr Attr;
106 enum {
107         AttrNameval,            /* name=val -- when matching, must have name=val */
108         AttrQuery,              /* name? -- when matching, must be present */
109         AttrDefault,            /* name=val -- when matching, if present must match INTERNAL */
110 };
111 struct Attr
112 {
113         int type;
114         Attr *next;
115         char *name;
116         char *val;
117 };
118
119 typedef int AuthGetkey(char*);
120
121 int     _attrfmt(Fmt*);
122 Attr    *_copyattr(Attr*);
123 Attr    *_delattr(Attr*, char*);
124 Attr    *_findattr(Attr*, char*);
125 void    _freeattr(Attr*);
126 Attr    *_mkattr(int, char*, char*, Attr*);
127 Attr    *_parseattr(char*);
128 char    *_strfindattr(Attr*, char*);
129 #pragma varargck type "A" Attr*
130
131 extern AuthInfo*        fauth_proxy(int, AuthRpc *rpc, AuthGetkey *getkey, char *params);
132 extern AuthInfo*        auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...);
133 extern int              auth_getkey(char*);
134 extern int              (*amount_getkey)(char*);
135 extern void             auth_freeAI(AuthInfo *ai);
136 extern int              auth_chuid(AuthInfo *ai, char *ns);
137 extern Chalstate        *auth_challenge(char*, ...);
138 extern AuthInfo*        auth_response(Chalstate*);
139 extern int              auth_respond(void*, uint, char*, uint, void*, uint, AuthGetkey*, char*, ...);
140 extern int              auth_respondAI(void *, uint, char*, uint, void*, uint, AuthInfo**, AuthGetkey*, 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 #pragma varargck argpos auth_proxy 3
150 #pragma varargck argpos auth_challenge 1
151 #pragma varargck argpos auth_respond 8
152 #pragma varargck argpos auth_respondAI 9
153 #pragma varargck argpos auth_getuserpasswd 2
154
155 #endif