1 #ifndef _XSASL_H_INCLUDED_
2 #define _XSASL_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /*	xsasl 3h
7 /* SUMMARY
8 /*	Postfix SASL plug-in interface
9 /* SYNOPSIS
10 /*	#include <xsasl.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15   * Utility library.
16   */
17 #include <argv.h>
18 #include <vstream.h>
19 #include <vstring.h>
20 
21  /*
22   * Generic server object. Specific instances extend this with their own
23   * private data.
24   */
25 typedef struct XSASL_SERVER {
26     void    (*free) (struct XSASL_SERVER *);
27     int     (*first) (struct XSASL_SERVER *, const char *, const char *, VSTRING *);
28     int     (*next) (struct XSASL_SERVER *, const char *, VSTRING *);
29     const char *(*get_mechanism_list) (struct XSASL_SERVER *);
30     const char *(*get_username) (struct XSASL_SERVER *);
31 } XSASL_SERVER;
32 
33 #define xsasl_server_free(server) (server)->free(server)
34 #define xsasl_server_first(server, method, init_resp, reply) \
35 	(server)->first((server), (method), (init_resp), (reply))
36 #define xsasl_server_next(server, request, reply) \
37 	(server)->next((server), (request), (reply))
38 #define xsasl_server_get_mechanism_list(server) \
39 	(server)->get_mechanism_list((server))
40 #define xsasl_server_get_username(server) \
41 	(server)->get_username((server))
42 
43  /*
44   * Generic server implementation. Specific instances extend this with their
45   * own private data.
46   */
47 typedef struct XSASL_SERVER_CREATE_ARGS {
48     VSTREAM *stream;
49     int     addr_family;
50     const char *server_addr;
51     const char *server_port;
52     const char *client_addr;
53     const char *client_port;
54     const char *service;
55     const char *user_realm;
56     const char *security_options;
57     int     tls_flag;
58 } XSASL_SERVER_CREATE_ARGS;
59 
60 typedef struct XSASL_SERVER_IMPL {
61     XSASL_SERVER *(*create) (struct XSASL_SERVER_IMPL *, XSASL_SERVER_CREATE_ARGS *);
62     void    (*done) (struct XSASL_SERVER_IMPL *);
63 } XSASL_SERVER_IMPL;
64 
65 extern XSASL_SERVER_IMPL *xsasl_server_init(const char *, const char *);
66 extern ARGV *xsasl_server_types(void);
67 
68 #define xsasl_server_create(impl, args) \
69 	(impl)->create((impl), (args))
70 #define XSASL_SERVER_CREATE(impl, args, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
71 	xsasl_server_create((impl), (((args)->a1), ((args)->a2), ((args)->a3), \
72 	((args)->a4), ((args)->a5), ((args)->a6), ((args)->a7), ((args)->a8), \
73 	((args)->a9), ((args)->a10), (args)))
74 #define xsasl_server_done(impl) (impl)->done((impl));
75 
76  /*
77   * Generic client object. Specific instances extend this with their own
78   * private data.
79   */
80 typedef struct XSASL_CLIENT {
81     void    (*free) (struct XSASL_CLIENT *);
82     int     (*first) (struct XSASL_CLIENT *, const char *, const char *, const char *, const char **, VSTRING *);
83     int     (*next) (struct XSASL_CLIENT *, const char *, VSTRING *);
84 } XSASL_CLIENT;
85 
86 #define xsasl_client_free(client) (client)->free(client)
87 #define xsasl_client_first(client, server, method, user, pass, init_resp) \
88 	(client)->first((client), (server), (method), (user), (pass), (init_resp))
89 #define xsasl_client_next(client, request, reply) \
90 	(client)->next((client), (request), (reply))
91 #define xsasl_client_set_password(client, user, pass) \
92 	(client)->set_password((client), (user), (pass))
93 
94  /*
95   * Generic client implementation. Specific instances extend this with their
96   * own private data.
97   */
98 typedef struct XSASL_CLIENT_CREATE_ARGS {
99     VSTREAM *stream;
100     const char *service;
101     const char *server_name;
102     const char *security_options;
103 } XSASL_CLIENT_CREATE_ARGS;
104 
105 typedef struct XSASL_CLIENT_IMPL {
106     XSASL_CLIENT *(*create) (struct XSASL_CLIENT_IMPL *, XSASL_CLIENT_CREATE_ARGS *);
107     void    (*done) (struct XSASL_CLIENT_IMPL *);
108 } XSASL_CLIENT_IMPL;
109 
110 extern XSASL_CLIENT_IMPL *xsasl_client_init(const char *, const char *);
111 extern ARGV *xsasl_client_types(void);
112 
113 #define xsasl_client_create(impl, args) \
114 	(impl)->create((impl), (args))
115 #define XSASL_CLIENT_CREATE(impl, args, a1, a2, a3, a4) \
116 	xsasl_client_create((impl), (((args)->a1), ((args)->a2), ((args)->a3), \
117 	((args)->a4), (args)))
118 #define xsasl_client_done(impl) (impl)->done((impl));
119 
120  /*
121   * Status codes.
122   */
123 #define XSASL_AUTH_OK	1		/* Success */
124 #define XSASL_AUTH_MORE	2		/* Need another c/s protocol exchange */
125 #define XSASL_AUTH_DONE	3		/* Authentication completed */
126 #define XSASL_AUTH_FORM	4		/* Cannot decode response */
127 #define XSASL_AUTH_FAIL	5		/* Error */
128 #define XSASL_AUTH_TEMP	6		/* Temporary error condition */
129 
130 /* LICENSE
131 /* .ad
132 /* .fi
133 /*	The Secure Mailer license must be distributed with this software.
134 /* AUTHOR(S)
135 /*	Wietse Venema
136 /*	IBM T.J. Watson Research
137 /*	P.O. Box 704
138 /*	Yorktown Heights, NY 10598, USA
139 /*
140 /*	Wietse Venema
141 /*	Google, Inc.
142 /*	111 8th Avenue
143 /*	New York, NY 10011, USA
144 /*--*/
145 
146 #endif
147