1 #ifndef CVM__SASL__H__
2 #define CVM__SASL__H__
3 
4 #include <bglibs/str.h>
5 
6 struct sasl_state;
7 
8 typedef int (*saslfn)(struct sasl_state*, const str* response, str* challenge);
9 
10 struct sasl_mechanism
11 {
12   const char* name;
13   const char* var;
14   const char* cvm;
15   saslfn start;
16   struct sasl_mechanism* next;
17 };
18 
19 struct sasl_state
20 {
21   saslfn response;
22   str init;
23   str username;
24   const char* domain;
25   const struct sasl_mechanism* mech;
26 };
27 
28 extern const struct sasl_mechanism* sasl_mechanisms;
29 extern int sasl_init(struct sasl_state*);
30 extern int sasl_start(struct sasl_state*,
31 		      const char* mechanism, const str* initresponse,
32 		      str* challenge);
33 
34 #define SASL_AUTH_OK 0		/* Authentication is complete */
35 #define SASL_AUTH_FAILED 1	/* Authentication failed (permanently) */
36 #define SASL_NO_MECH 2		/* Invalid or unknown mechanism name */
37 #define SASL_TEMP_FAIL 3	/* Temporary or internal failure */
38 #define SASL_CHALLENGE 4	/* Send challenge to client, wait for response */
39 #define SASL_RESP_REQUIRED 5	/* A response was required but not given */
40 #define SASL_RESP_NOTALLOWED 6	/* A (initial) response was given but not allowed */
41 #define SASL_RESP_BAD 7		/* The response was invalid */
42 #define SASL_RESP_EOF 8		/* EOF while waiting for response */
43 
44 struct ibuf;
45 struct obuf;
46 
47 struct sasl_auth
48 {
49   struct sasl_state state;
50   const char* prefix;
51   const char* suffix;
52   struct ibuf* in;
53   struct obuf* out;
54 };
55 
56 int sasl_auth_caps(str* caps);
57 int sasl_auth_init(struct sasl_auth* sa);
58 int sasl_auth2(struct sasl_auth* sa,
59 	       const char* mechanism, const char* iresponse);
60 int sasl_auth1(struct sasl_auth* sa, const str* arg);
61 const char* sasl_auth_msg(int* code);
62 
63 #endif
64