1 /* This is a proposed C API for support of SASL
3 *********************************IMPORTANT*******************************
4 * send email to chris.newman@innosoft.com and cyrus-bugs@andrew.cmu.edu *
5 * if you need to add new error codes, callback types, property values, *
6 * etc. It is important to keep the multiple implementations of this *
7 * API from diverging. *
8 *********************************IMPORTANT*******************************
11 * sasl_conn_t Context for a SASL connection negotiation
12 * sasl_ssf_t Security layer Strength Factor
13 * sasl_callback_t A typed client/server callback function and context
14 * sasl_interact_t A client interaction descriptor
15 * sasl_secret_t A client password
16 * sasl_rand_t Random data context structure
17 * sasl_security_properties_t An application's required security level
20 * sasl_getopt_t client/server: Get an option value
21 * sasl_logmsg_t client/server: Log message handler
22 * sasl_getsimple_t client: Get user/language list
23 * sasl_getsecret_t client: Get authentication secret
24 * sasl_chalprompt_t client: Display challenge and prompt for response
26 * Server only Callbacks:
27 * sasl_authorize_t user authorization policy callback
28 * sasl_getconfpath_t get path to search for config file
29 * sasl_server_userdb_checkpass check password and auxprops in userdb
30 * sasl_server_userdb_setpass set password in userdb
31 * sasl_server_canon_user canonicalize username routine
33 * Client/Server Function Summary:
34 * sasl_done Release all SASL global state
35 * sasl_dispose Connection done: Dispose of sasl_conn_t
36 * sasl_getprop Get property (e.g., user name, security layer info)
37 * sasl_setprop Set property (e.g., external ssf)
38 * sasl_errdetail Generate string from last error on connection
39 * sasl_errstring Translate sasl error code to a string
40 * sasl_encode Encode data to send using security layer
41 * sasl_decode Decode data received using security layer
44 * sasl_encode64 Encode data to send using MIME base64 encoding
45 * sasl_decode64 Decode data received using MIME base64 encoding
46 * sasl_erasebuffer Erase a buffer
48 * Client Function Summary:
49 * sasl_client_init Load and initialize client plug-ins (call once)
50 * sasl_client_new Initialize client connection context: sasl_conn_t
51 * sasl_client_start Select mechanism for connection
52 * sasl_client_step Perform one authentication step
54 * Server Function Summary
55 * sasl_server_init Load and initialize server plug-ins (call once)
56 * sasl_server_new Initialize server connection context: sasl_conn_t
57 * sasl_listmech Create list of available mechanisms
58 * sasl_server_start Begin an authentication exchange
59 * sasl_server_step Perform one authentication exchange step
60 * sasl_checkpass Check a plaintext passphrase
61 * sasl_checkapop Check an APOP challenge/response (uses pseudo "APOP"
62 * mechanism similar to CRAM-MD5 mechanism; optional)
63 * sasl_user_exists Check if user exists
64 * sasl_setpass Change a password or add a user entry
65 * sasl_auxprop_request Request auxiliary properties
66 * sasl_auxprop_getctx Get auxiliary property context for connection
67 * sasl_auxprop_store Store a set of auxiliary properties
70 * 1. client calls sasl_client_init() at startup to load plug-ins
71 * 2. when connection formed, call sasl_client_new()
72 * 3. once list of supported mechanisms received from server, client
73 * calls sasl_client_start(). goto 4a
74 * 4. client calls sasl_client_step()
75 * [4a. If SASL_INTERACT, fill in prompts and goto 4
76 * -- doesn't happen if callbacks provided]
77 * 4b. If SASL error, goto 7 or 3
78 * 4c. If SASL_OK, continue or goto 6 if last server response was success
79 * 5. send message to server, wait for response
80 * 5a. On data or success with server response, goto 4
81 * 5b. On failure goto 7 or 3
82 * 5c. On success with no server response continue
83 * 6. continue with application protocol until connection closes
84 * call sasl_getprop/sasl_encode/sasl_decode() if using security layer
85 * 7. call sasl_dispose(), may return to step 2
86 * 8. call sasl_done() when program terminates
89 * 1. call sasl_server_init() at startup to load plug-ins
90 * 2. On connection, call sasl_server_new()
91 * 3. call sasl_listmech() and send list to client]
92 * 4. after client AUTH command, call sasl_server_start(), goto 5a
93 * 5. call sasl_server_step()
94 * 5a. If SASL_CONTINUE, output to client, wait response, repeat 5
95 * 5b. If SASL error, then goto 7
96 * 5c. If SASL_OK, move on
97 * 6. continue with application protocol until connection closes
98 * call sasl_getprop to get username
99 * call sasl_getprop/sasl_encode/sasl_decode() if using security layer
100 * 7. call sasl_dispose(), may return to step 2
101 * 8. call sasl_done() when program terminates
103 *************************************************
104 * IMPORTANT NOTE: server realms / username syntax
106 * If a user name contains a "@", then the rightmost "@" in the user name
107 * separates the account name from the realm in which this account is
108 * located. A single server may support multiple realms. If the
109 * server knows the realm at connection creation time (e.g., a server
110 * with multiple IP addresses tightly binds one address to a specific
111 * realm) then that realm must be passed in the user_realm field of
112 * the sasl_server_new call. If user_realm is non-empty and an
113 * unqualified user name is supplied, then the canon_user facility is
114 * expected to append "@" and user_realm to the user name. The canon_user
115 * facility may treat other characters such as "%" as equivalent to "@".
117 * If the server forbids the use of "@" in user names for other
118 * purposes, this simplifies security validation.
124 /* Keep in sync with win32/common.mak */
125 #define SASL_VERSION_MAJOR 2
126 #define SASL_VERSION_MINOR 1
127 #define SASL_VERSION_STEP 23
129 /* A convenience macro: same as was defined in the OpenLDAP LDAPDB */
130 #define SASL_VERSION_FULL ((SASL_VERSION_MAJOR << 16) |\
131 (SASL_VERSION_MINOR << 8) | SASL_VERSION_STEP)
139 /* SASL result codes: */
140 #define SASL_CONTINUE 1 /* another step is needed in authentication */
141 #define SASL_OK 0 /* successful result */
142 #define SASL_FAIL -1 /* generic failure */
143 #define SASL_NOMEM -2 /* memory shortage failure */
144 #define SASL_BUFOVER -3 /* overflowed buffer */
145 #define SASL_NOMECH -4 /* mechanism not supported */
146 #define SASL_BADPROT -5 /* bad protocol / cancel */
147 #define SASL_NOTDONE -6 /* can't request info until later in exchange */
148 #define SASL_BADPARAM -7 /* invalid parameter supplied */
149 #define SASL_TRYAGAIN -8 /* transient failure (e.g., weak key) */
150 #define SASL_BADMAC -9 /* integrity check failed */
151 #define SASL_NOTINIT -12 /* SASL library not initialized */
152 /* -- client only codes -- */
153 #define SASL_INTERACT 2 /* needs user interaction */
154 #define SASL_BADSERV -10 /* server failed mutual authentication step */
155 #define SASL_WRONGMECH -11 /* mechanism doesn't support requested feature */
156 /* -- server only codes -- */
157 #define SASL_BADAUTH -13 /* authentication failure */
158 #define SASL_NOAUTHZ -14 /* authorization failure */
159 #define SASL_TOOWEAK -15 /* mechanism too weak for this user */
160 #define SASL_ENCRYPT -16 /* encryption needed to use mechanism */
161 #define SASL_TRANS -17 /* One time use of a plaintext password will
162 enable requested mechanism for user */
163 #define SASL_EXPIRED -18 /* passphrase expired, has to be reset */
164 #define SASL_DISABLED -19 /* account disabled */
165 #define SASL_NOUSER -20 /* user not found */
166 #define SASL_BADVERS -23 /* version mismatch with plug-in */
167 #define SASL_UNAVAIL -24 /* remote authentication server unavailable */
168 #define SASL_NOVERIFY -26 /* user exists, but no verifier for user */
169 /* -- codes for password setting -- */
170 #define SASL_PWLOCK -21 /* passphrase locked */
171 #define SASL_NOCHANGE -22 /* requested change was not needed */
172 #define SASL_WEAKPASS -27 /* passphrase is too weak for security policy */
173 #define SASL_NOUSERPASS -28 /* user supplied passwords not permitted */
174 #define SASL_BADBINDING -29 /* channel binding failure */
176 /* max size of a sasl mechanism name */
177 #define SASL_MECHNAMEMAX 20
180 /* Define to have the same layout as a WSABUF */
181 #ifndef STRUCT_IOVEC_DEFINED
182 #define STRUCT_IOVEC_DEFINED 1
189 struct iovec; /* Defined in OS headers */
193 /* per-connection SASL negotiation state for client or server
195 typedef struct sasl_conn sasl_conn_t;
197 /* Plain text password structure.
198 * len is the length of the password, data is the text.
200 typedef struct sasl_secret {
202 unsigned char data[1]; /* variable sized */
205 /* random data context structure
207 typedef struct sasl_rand_s sasl_rand_t;
213 /****************************
214 * Configure Basic Services *
215 ****************************/
217 /* the following functions are used to adjust how allocation and mutexes work
218 * they must be called before all other SASL functions:
221 /* memory allocation functions which may optionally be replaced:
223 typedef void *sasl_malloc_t(unsigned long);
224 typedef void *sasl_calloc_t(unsigned long, unsigned long);
225 typedef void *sasl_realloc_t(void *, unsigned long);
226 typedef void sasl_free_t(void *);
228 LIBSASL_API void sasl_set_alloc(sasl_malloc_t *,
233 /* mutex functions which may optionally be replaced:
234 * sasl_mutex_alloc allocates a mutex structure
235 * sasl_mutex_lock blocks until mutex locked
236 * returns -1 on deadlock or parameter error
237 * returns 0 on success
238 * sasl_mutex_unlock unlocks mutex if it's locked
239 * returns -1 if not locked or parameter error
240 * returns 0 on success
241 * sasl_mutex_free frees a mutex structure
243 typedef void *sasl_mutex_alloc_t(void);
244 typedef int sasl_mutex_lock_t(void *mutex);
245 typedef int sasl_mutex_unlock_t(void *mutex);
246 typedef void sasl_mutex_free_t(void *mutex);
247 LIBSASL_API void sasl_set_mutex(sasl_mutex_alloc_t *, sasl_mutex_lock_t *,
248 sasl_mutex_unlock_t *, sasl_mutex_free_t *);
250 /*****************************
251 * Security preference types *
252 *****************************/
254 /* security layer strength factor -- an unsigned integer usable by the caller
255 * to specify approximate security layer strength desired. Roughly
256 * correlated to effective key length for encryption.
258 * 1 = integrity protection only
259 * 40 = 40-bit DES or 40-bit RC2/RC4
262 * 128 = 128-bit RC2/RC4/BLOWFISH
265 typedef unsigned sasl_ssf_t;
267 /* usage flags provided to sasl_server_new and sasl_client_new:
269 #define SASL_SUCCESS_DATA 0x0004 /* server supports data on success */
270 #define SASL_NEED_PROXY 0x0008 /* require a mech that allows proxying */
272 /***************************
273 * Security Property Types *
274 ***************************/
276 /* Structure specifying the client or server's security policy
277 * and optional additional properties.
280 /* These are the various security flags apps can specify. */
281 /* NOPLAINTEXT -- don't permit mechanisms susceptible to simple
282 * passive attack (e.g., PLAIN, LOGIN)
283 * NOACTIVE -- protection from active (non-dictionary) attacks
284 * during authentication exchange.
285 * Authenticates server.
286 * NODICTIONARY -- don't permit mechanisms susceptible to passive
288 * FORWARD_SECRECY -- require forward secrecy between sessions
289 * (breaking one won't help break next)
290 * NOANONYMOUS -- don't permit mechanisms that allow anonymous login
291 * PASS_CREDENTIALS -- require mechanisms which pass client
292 * credentials, and allow mechanisms which can pass
293 * credentials to do so
294 * MUTUAL_AUTH -- require mechanisms which provide mutual
297 #define SASL_SEC_NOPLAINTEXT 0x0001
298 #define SASL_SEC_NOACTIVE 0x0002
299 #define SASL_SEC_NODICTIONARY 0x0004
300 #define SASL_SEC_FORWARD_SECRECY 0x0008
301 #define SASL_SEC_NOANONYMOUS 0x0010
302 #define SASL_SEC_PASS_CREDENTIALS 0x0020
303 #define SASL_SEC_MUTUAL_AUTH 0x0040
304 #define SASL_SEC_MAXIMUM 0x00FF
306 typedef struct sasl_security_properties
308 /* security strength factor
309 * min_ssf = minimum acceptable final level
310 * max_ssf = maximum acceptable final level
315 /* Maximum security layer receive buffer size.
316 * 0=security layer not supported
320 /* bitfield for attacks to protect against */
321 unsigned security_flags;
323 /* NULL terminated array of additional property names, values */
324 const char **property_names;
325 const char **property_values;
326 } sasl_security_properties_t;
333 * Extensible type for a client/server callbacks
334 * id -- identifies callback type
335 * proc -- procedure call arguments vary based on id
336 * context -- context passed to procedure
338 /* Note that any memory that is allocated by the callback needs to be
339 * freed by the application, be it via function call or interaction.
341 * It may be freed after sasl_*_step returns SASL_OK. if the mechanism
342 * requires this information to persist (for a security layer, for example)
343 * it must maintain a private copy.
345 typedef struct sasl_callback {
346 /* Identifies the type of the callback function.
347 * Mechanisms must ignore callbacks with id's they don't recognize.
350 int (*proc)(); /* Callback function. Types of arguments vary by 'id' */
354 /* callback ids & functions:
356 #define SASL_CB_LIST_END 0 /* end of list */
358 /* option reading callback -- this allows a SASL configuration to be
359 * encapsulated in the caller's configuration system. Some implementations
360 * may use default config file(s) if this is omitted. Configuration items
361 * may be plugin-specific and are arbitrary strings.
364 * context -- option context from callback record
365 * plugin_name -- name of plugin (NULL = general SASL option)
366 * option -- name of option
368 * result -- set to result which persists until next getopt in
369 * same thread, unchanged if option not found
370 * len -- length of result (may be NULL)
372 * SASL_OK -- no error
375 typedef int sasl_getopt_t(void *context, const char *plugin_name,
377 const char **result, unsigned *len);
378 #define SASL_CB_GETOPT 1
380 /* Logging levels for use with the logging callback function. */
381 #define SASL_LOG_NONE 0 /* don't log anything */
382 #define SASL_LOG_ERR 1 /* log unusual errors (default) */
383 #define SASL_LOG_FAIL 2 /* log all authentication failures */
384 #define SASL_LOG_WARN 3 /* log non-fatal warnings */
385 #define SASL_LOG_NOTE 4 /* more verbose than LOG_WARN */
386 #define SASL_LOG_DEBUG 5 /* more verbose than LOG_NOTE */
387 #define SASL_LOG_TRACE 6 /* traces of internal protocols */
388 #define SASL_LOG_PASS 7 /* traces of internal protocols, including
391 /* logging callback -- this allows plugins and the middleware to
392 * log operations they perform.
394 * context -- logging context from the callback record
395 * level -- logging level; see above
396 * message -- message to log
398 * SASL_OK -- no error
401 typedef int sasl_log_t(void *context,
403 const char *message);
404 #define SASL_CB_LOG 2
406 /* getpath callback -- this allows applications to specify the
407 * colon-separated path to search for plugins (by default,
408 * taken from an implementation-specific location).
410 * context -- getpath context from the callback record
412 * path -- colon seperated path
414 * SASL_OK -- no error
417 typedef int sasl_getpath_t(void *context,
420 #define SASL_CB_GETPATH 3
422 /* verify file callback -- this allows applications to check if they
423 * want SASL to use files, file by file. This is intended to allow
424 * applications to sanity check the environment to make sure plugins
425 * or the configuration file can't be written to, etc.
427 * context -- verifypath context from the callback record
428 * file -- full path to file to verify
429 * type -- type of file to verify (see below)
432 * SASL_OK -- no error (file can safely be used)
433 * SASL_CONTINUE -- continue WITHOUT using this file
437 /* these are the types of files libsasl will ask about */
439 SASL_VRFY_PLUGIN=0, /* a DLL/shared library plug-in */
440 SASL_VRFY_CONF=1, /* a configuration file */
441 SASL_VRFY_PASSWD=2, /* a password storage file/db */
442 SASL_VRFY_OTHER=3 /* some other file */
443 } sasl_verify_type_t;
445 typedef int sasl_verifyfile_t(void *context,
446 const char *file, sasl_verify_type_t type);
447 #define SASL_CB_VERIFYFILE 4
449 /* getconfpath callback -- this allows applications to specify the
450 * colon-separated path to search for config files (by default,
451 * taken from the SASL_CONF_PATH environment variable).
453 * context -- getconfpath context from the callback record
455 * path -- colon seperated path (allocated on the heap; the
456 * library will free it using the sasl_free_t *
457 * passed to sasl_set_callback, or the standard free()
460 * SASL_OK -- no error
463 typedef int sasl_getconfpath_t(void *context,
466 #define SASL_CB_GETCONFPATH 5
468 /* client/user interaction callbacks:
470 /* Simple prompt -- result must persist until next call to getsimple on
471 * same connection or until connection context is disposed
473 * context -- context from callback structure
476 * result -- set to NUL terminated string
478 * len -- length of result
481 typedef int sasl_getsimple_t(void *context, int id,
482 const char **result, unsigned *len);
483 #define SASL_CB_USER 0x4001 /* client user identity to login as */
484 #define SASL_CB_AUTHNAME 0x4002 /* client authentication name */
485 #define SASL_CB_LANGUAGE 0x4003 /* comma separated list of RFC 1766
486 * language codes in order of preference
487 * to be used to localize client prompts
488 * or server error codes */
489 #define SASL_CB_CNONCE 0x4007 /* caller supplies client-nonce
490 * primarily for testing purposes */
492 /* get a sasl_secret_t (plaintext password with length)
494 * conn -- connection context
495 * context -- context from callback structure
498 * psecret -- set to NULL to cancel
499 * set to password structure which must persist until
500 * next call to getsecret in same connection, but middleware
501 * will erase password data when it's done with it.
504 typedef int sasl_getsecret_t(sasl_conn_t *conn, void *context, int id,
505 sasl_secret_t **psecret);
506 #define SASL_CB_PASS 0x4004 /* client passphrase-based secret */
509 /* prompt for input in response to a challenge.
511 * context -- context from callback structure
513 * challenge -- server challenge
515 * result -- NUL terminated result, NULL = user cancel
516 * len -- length of result
519 typedef int sasl_chalprompt_t(void *context, int id,
520 const char *challenge,
521 const char *prompt, const char *defresult,
522 const char **result, unsigned *len);
523 #define SASL_CB_ECHOPROMPT 0x4005 /* challenge and client enterred result */
524 #define SASL_CB_NOECHOPROMPT 0x4006 /* challenge and client enterred result */
526 /* prompt (or autoselect) the realm to do authentication in.
527 * may get a list of valid realms.
529 * context -- context from callback structure
531 * availrealms -- available realms; string list; NULL terminated
534 * result -- NUL terminated realm; NULL is equivalent to ""
536 * result must persist until the next callback
538 typedef int sasl_getrealm_t(void *context, int id,
539 const char **availrealms,
540 const char **result);
541 #define SASL_CB_GETREALM (0x4008) /* realm to attempt authentication in */
546 /* improved callback to verify authorization;
547 * canonicalization now handled elsewhere
548 * conn -- connection context
549 * requested_user -- the identity/username to authorize (NUL terminated)
550 * rlen -- length of requested_user
551 * auth_identity -- the identity associated with the secret (NUL terminated)
552 * alen -- length of auth_identity
553 * default_realm -- default user realm, as passed to sasl_server_new if
554 * urlen -- length of default realm
555 * propctx -- auxiliary properties
556 * returns SASL_OK on success,
557 * SASL_NOAUTHZ or other SASL response on failure
559 typedef int sasl_authorize_t(sasl_conn_t *conn,
561 const char *requested_user, unsigned rlen,
562 const char *auth_identity, unsigned alen,
563 const char *def_realm, unsigned urlen,
564 struct propctx *propctx);
565 #define SASL_CB_PROXY_POLICY 0x8001
567 /* functions for "userdb" based plugins to call to get/set passwords.
568 * the location for the passwords is determined by the caller or middleware.
569 * plug-ins may get passwords from other locations.
572 /* callback to verify a plaintext password against the caller-supplied
573 * user database. This is necessary to allow additional <method>s for
574 * encoding of the userPassword property.
575 * user -- NUL terminated user name with user@realm syntax
576 * pass -- password to check (may not be NUL terminated)
577 * passlen -- length of password to check
578 * propctx -- auxiliary properties for user
580 typedef int sasl_server_userdb_checkpass_t(sasl_conn_t *conn,
585 struct propctx *propctx);
586 #define SASL_CB_SERVER_USERDB_CHECKPASS (0x8005)
588 /* callback to store/change a plaintext password in the user database
589 * user -- NUL terminated user name with user@realm syntax
590 * pass -- password to store (may not be NUL terminated)
591 * passlen -- length of password to store
592 * propctx -- auxiliary properties (not stored)
593 * flags -- see SASL_SET_* flags below (SASL_SET_CREATE optional)
595 typedef int sasl_server_userdb_setpass_t(sasl_conn_t *conn,
600 struct propctx *propctx,
602 #define SASL_CB_SERVER_USERDB_SETPASS (0x8006)
604 /* callback for a server-supplied user canonicalization function.
606 * This function is called directly after the mechanism has the
607 * authentication and authorization IDs. It is called before any
608 * User Canonicalization plugin is called. It has the responsibility
609 * of copying its output into the provided output buffers.
611 * in, inlen -- user name to canonicalize, may not be NUL terminated
612 * may be same buffer as out
613 * flags -- not currently used, supplied by auth mechanism
614 * user_realm -- the user realm (may be NULL in case of client)
615 * out -- buffer to copy user name
616 * out_max -- max length of user name
617 * out_len -- set to length of user name
621 * SASL_BADPROT username contains invalid character
624 /* User Canonicalization Function Flags */
626 #define SASL_CU_NONE 0x00 /* Not a valid flag to pass */
627 /* One of the following two is required */
628 #define SASL_CU_AUTHID 0x01
629 #define SASL_CU_AUTHZID 0x02
631 typedef int sasl_canon_user_t(sasl_conn_t *conn,
633 const char *in, unsigned inlen,
635 const char *user_realm,
637 unsigned out_max, unsigned *out_len);
639 #define SASL_CB_CANON_USER (0x8007)
641 /**********************************
642 * Common Client/server functions *
643 **********************************/
645 /* Types of paths to set (see sasl_set_path below). */
646 #define SASL_PATH_TYPE_PLUGIN 0
647 #define SASL_PATH_TYPE_CONFIG 1
649 /* a simpler way to set plugin path or configuration file path
650 * without the need to set sasl_getpath_t callback.
652 * This function can be called before sasl_server_init/sasl_client_init.
654 LIBSASL_API int sasl_set_path (int path_type, char * path);
656 /* get sasl library version information
657 * implementation is a vendor-defined string
658 * version is a vender-defined representation of the version #.
660 * This function is being deprecated in favor of sasl_version_info. */
661 LIBSASL_API void sasl_version(const char **implementation,
664 /* Extended version of sasl_version().
666 * This function is to be used
667 * for library version display and logging
668 * for bug workarounds in old library versions
670 * The sasl_version_info is not to be used for API feature detection.
672 * All parameters are optional. If NULL is specified, the value is not returned.
674 LIBSASL_API void sasl_version_info (const char **implementation,
675 const char **version_string,
681 /* dispose of all SASL plugins. Connection
682 * states have to be disposed of before calling this.
684 LIBSASL_API void sasl_done(void);
686 /* dispose connection state, sets it to NULL
687 * checks for pointer to NULL
689 LIBSASL_API void sasl_dispose(sasl_conn_t **pconn);
691 /* translate an error number into a string
693 * saslerr -- the error number
694 * langlist -- comma separated list of RFC 1766 languages (may be NULL)
696 * outlang -- the language actually used (may be NULL if don't care)
698 * the error message in UTF-8 (only the US-ASCII subset if langlist is NULL)
700 LIBSASL_API const char *sasl_errstring(int saslerr,
701 const char *langlist,
702 const char **outlang);
704 /* get detail about the last error that occurred on a connection
705 * text is sanitized so it's suitable to send over the wire
706 * (e.g., no distinction between SASL_BADAUTH and SASL_NOUSER)
708 * conn -- mandatory connection context
710 * the error message in UTF-8 (only the US-ASCII subset permitted if no
711 * SASL_CB_LANGUAGE callback is present)
713 LIBSASL_API const char *sasl_errdetail(sasl_conn_t *conn);
715 /* set the error string which will be returned by sasl_errdetail() using
716 * syslog()-style formatting (e.g. printf-style with %m as most recent
719 * primarily for use by server callbacks such as the sasl_authorize_t
720 * callback and internally to plug-ins
722 * This will also trigger a call to the SASL logging callback (if any)
723 * with a level of SASL_LOG_FAIL unless the SASL_NOLOG flag is set.
725 * Messages should be sensitive to the current language setting. If there
726 * is no SASL_CB_LANGUAGE callback messages MUST be US-ASCII otherwise UTF-8
727 * is used and use of RFC 2482 for mixed-language text is encouraged.
729 * if conn is NULL, function does nothing
731 LIBSASL_API void sasl_seterror(sasl_conn_t *conn, unsigned flags,
732 const char *fmt, ...);
733 #define SASL_NOLOG 0x01
735 /* get property from SASL connection state
736 * propnum -- property number
737 * pvalue -- pointer to value
739 * SASL_OK -- no error
740 * SASL_NOTDONE -- property not available yet
741 * SASL_BADPARAM -- bad property number
743 LIBSASL_API int sasl_getprop(sasl_conn_t *conn, int propnum,
744 const void **pvalue);
745 #define SASL_USERNAME 0 /* pointer to NUL terminated user name */
746 #define SASL_SSF 1 /* security layer security strength factor,
747 * if 0, call to sasl_encode, sasl_decode
749 #define SASL_MAXOUTBUF 2 /* security layer max output buf unsigned */
750 #define SASL_DEFUSERREALM 3 /* default realm passed to server_new */
751 /* or set with setprop */
752 #define SASL_GETOPTCTX 4 /* context for getopt callback */
753 #define SASL_CALLBACK 7 /* current callback function list */
754 #define SASL_IPLOCALPORT 8 /* iplocalport string passed to server_new */
755 #define SASL_IPREMOTEPORT 9 /* ipremoteport string passed to server_new */
757 /* This returns a string which is either empty or has an error message
758 * from sasl_seterror (e.g., from a plug-in or callback). It differs
759 * from the result of sasl_errdetail() which also takes into account the
760 * last return status code.
762 #define SASL_PLUGERR 10
764 /* a handle to any delegated credentials or NULL if none is present
765 * is returned by the mechanism. The user will probably need to know
766 * which mechanism was used to actually known how to make use of them
767 * currently only implemented for the gssapi mechanism */
768 #define SASL_DELEGATEDCREDS 11
770 #define SASL_SERVICE 12 /* service passed to sasl_*_new */
771 #define SASL_SERVERFQDN 13 /* serverFQDN passed to sasl_*_new */
772 #define SASL_AUTHSOURCE 14 /* name of auth source last used, useful
773 * for failed authentication tracking */
774 #define SASL_MECHNAME 15 /* active mechanism name, if any */
775 #define SASL_AUTHUSER 16 /* authentication/admin user */
776 #define SASL_APPNAME 17 /* application name (used for logging/
777 configuration), same as appname parameter
778 to sasl_server_init */
780 /* GSS-API credential handle for sasl_client_step() or sasl_server_step().
781 * The application is responsible for releasing this credential handle. */
782 #define SASL_GSS_CREDS 18
784 /* GSS name (gss_name_t) of the peer, as output by gss_inquire_context()
785 * or gss_accept_sec_context().
786 * On server end this is similar to SASL_USERNAME, but the gss_name_t
787 * structure can contain additional attributes associated with the peer.
789 #define SASL_GSS_PEER_NAME 19
791 /* Local GSS name (gss_name_t) as output by gss_inquire_context(). This
792 * is particularly useful for servers that respond to multiple names. */
793 #define SASL_GSS_LOCAL_NAME 20
795 /* Channel binding information. Memory is managed by the caller. */
796 typedef struct sasl_channel_binding {
800 const unsigned char *data;
801 } sasl_channel_binding_t;
803 #define SASL_CHANNEL_BINDING 21
805 /* set property in SASL connection state
807 * SASL_OK -- value set
808 * SASL_BADPARAM -- invalid property or value
810 LIBSASL_API int sasl_setprop(sasl_conn_t *conn,
813 #define SASL_SSF_EXTERNAL 100 /* external SSF active (sasl_ssf_t *) */
814 #define SASL_SEC_PROPS 101 /* sasl_security_properties_t */
815 #define SASL_AUTH_EXTERNAL 102 /* external authentication ID (const char *) */
817 /* If the SASL_AUTH_EXTERNAL value is non-NULL, then a special version of the
818 * EXTERNAL mechanism is enabled (one for server-embedded EXTERNAL mechanisms).
819 * Otherwise, the EXTERNAL mechanism will be absent unless a plug-in
820 * including EXTERNAL is present.
823 /* do precalculations during an idle period or network round trip
824 * may pass NULL to precompute for some mechanisms prior to connect
825 * returns 1 if action taken, 0 if no action taken
827 LIBSASL_API int sasl_idle(sasl_conn_t *conn);
833 /* list of client interactions with user for caller to fill in
835 typedef struct sasl_interact {
836 unsigned long id; /* same as client/user callback ID */
837 const char *challenge; /* presented to user (e.g. OTP challenge) */
838 const char *prompt; /* presented to user (e.g. "Username: ") */
839 const char *defresult; /* default result string */
840 const void *result; /* set to point to result */
841 unsigned len; /* set to length of result */
844 /* initialize the SASL client drivers
845 * callbacks -- base callbacks for all client connections;
846 * must include getopt callback
849 * SASL_NOMEM -- Not enough memory
850 * SASL_BADVERS -- Mechanism version mismatch
851 * SASL_BADPARAM -- missing getopt callback or error in config file
852 * SASL_NOMECH -- No mechanisms available
855 LIBSASL_API int sasl_client_init(const sasl_callback_t *callbacks);
857 /* initialize a client exchange based on the specified mechanism
858 * service -- registered name of the service using SASL (e.g. "imap")
859 * serverFQDN -- the fully qualified domain name of the server
860 * iplocalport -- client IPv4/IPv6 domain literal string with port
861 * (if NULL, then mechanisms requiring IPaddr are disabled)
862 * ipremoteport -- server IPv4/IPv6 domain literal string with port
863 * (if NULL, then mechanisms requiring IPaddr are disabled)
864 * prompt_supp -- list of client interactions supported
865 * may also include sasl_getopt_t context & call
866 * NULL prompt_supp = user/pass via SASL_INTERACT only
867 * NULL proc = interaction supported via SASL_INTERACT
868 * flags -- server usage flags (see above)
870 * pconn -- connection negotiation structure
871 * pointer to NULL => allocate new
875 * SASL_NOMECH -- no mechanism meets requested properties
876 * SASL_NOMEM -- not enough memory
878 LIBSASL_API int sasl_client_new(const char *service,
879 const char *serverFQDN,
880 const char *iplocalport,
881 const char *ipremoteport,
882 const sasl_callback_t *prompt_supp,
884 sasl_conn_t **pconn);
886 /* select a mechanism for a connection
887 * mechlist -- mechanisms server has available (punctuation ignored)
888 * if NULL, then discard cached info and retry last mech
890 * prompt_need -- on SASL_INTERACT, list of prompts needed to continue
891 * may be NULL if callbacks provided
892 * clientout -- the initial client response to send to the server
893 * will be valid until next call to client_start/client_step
894 * NULL if mech doesn't include initial client challenge
895 * mech -- set to mechansm name of selected mechanism (may be NULL)
899 * SASL_NOMEM -- not enough memory
900 * SASL_NOMECH -- no mechanism meets requested properties
901 * SASL_INTERACT -- user interaction needed to fill in prompt_need list
903 LIBSASL_API int sasl_client_start(sasl_conn_t *conn,
904 const char *mechlist,
905 sasl_interact_t **prompt_need,
906 const char **clientout,
907 unsigned *clientoutlen,
910 /* do a single authentication step.
911 * serverin -- the server message received by the client, MUST have a NUL
912 * sentinel, not counted by serverinlen
914 * prompt_need -- on SASL_INTERACT, list of prompts needed to continue
915 * clientout -- the client response to send to the server
916 * will be valid until next call to client_start/client_step
920 * SASL_INTERACT -- user interaction needed to fill in prompt_need list
921 * SASL_BADPROT -- server protocol incorrect/cancelled
922 * SASL_BADSERV -- server failed mutual auth
924 LIBSASL_API int sasl_client_step(sasl_conn_t *conn,
925 const char *serverin,
926 unsigned serverinlen,
927 sasl_interact_t **prompt_need,
928 const char **clientout,
929 unsigned *clientoutlen);
935 /* initialize server drivers, done once per process
936 * callbacks -- callbacks for all server connections; must include
938 * appname -- name of calling application (for lower level logging)
940 * state -- server state
943 * SASL_BADPARAM -- error in config file
944 * SASL_NOMEM -- memory failure
945 * SASL_BADVERS -- Mechanism version mismatch
947 LIBSASL_API int sasl_server_init(const sasl_callback_t *callbacks,
948 const char *appname);
951 * a.b.c.d;p where a-d are 0-255 and p is 0-65535 port number.
952 * e:f:g:h:i:j:k:l;p where e-l are 0000-ffff lower-case hexidecimal
953 * e:f:g:h:i:j:a.b.c.d;p alternate syntax for previous
955 * Note that one or more "0" fields in f-k can be replaced with "::"
956 * Thus: e:f:0000:0000:0000:j:k:l;p
957 * can be abbreviated: e:f::j:k:l;p
959 * A buffer of size 52 is adequate for the longest format with NUL terminator.
962 /* create context for a single SASL connection
963 * service -- registered name of the service using SASL (e.g. "imap")
964 * serverFQDN -- Fully qualified domain name of server. NULL means use
965 * gethostname() or equivalent.
966 * Useful for multi-homed servers.
967 * user_realm -- permits multiple user realms on server, NULL = default
968 * iplocalport -- server IPv4/IPv6 domain literal string with port
969 * (if NULL, then mechanisms requiring IPaddr are disabled)
970 * ipremoteport -- client IPv4/IPv6 domain literal string with port
971 * (if NULL, then mechanisms requiring IPaddr are disabled)
972 * callbacks -- callbacks (e.g., authorization, lang, new getopt context)
973 * flags -- usage flags (see above)
975 * pconn -- new connection context
979 * SASL_NOMEM -- not enough memory
981 LIBSASL_API int sasl_server_new(const char *service,
982 const char *serverFQDN,
983 const char *user_realm,
984 const char *iplocalport,
985 const char *ipremoteport,
986 const sasl_callback_t *callbacks,
988 sasl_conn_t **pconn);
990 /* Return an array of NUL-terminated strings, terminated by a NULL pointer,
991 * which lists all possible mechanisms that the library can supply
993 * Returns NULL on failure. */
994 LIBSASL_API const char ** sasl_global_listmech(void);
996 /* This returns a list of mechanisms in a NUL-terminated string
997 * conn -- the connection to list mechanisms for (either client
999 * user -- restricts mechanisms to those available to that user
1000 * (may be NULL, not used for client case)
1001 * prefix -- appended to beginning of result
1002 * sep -- appended between mechanisms
1003 * suffix -- appended to end of result
1005 * result -- NUL terminated result which persists until next
1006 * call to sasl_listmech for this sasl_conn_t
1007 * plen -- gets length of result (excluding NUL), may be NULL
1008 * pcount -- gets number of mechanisms, may be NULL
1011 * SASL_OK -- success
1012 * SASL_NOMEM -- not enough memory
1013 * SASL_NOMECH -- no enabled mechanisms
1015 LIBSASL_API int sasl_listmech(sasl_conn_t *conn,
1020 const char **result,
1024 /* start a mechanism exchange within a connection context
1025 * mech -- the mechanism name client requested
1026 * clientin -- client initial response (NUL terminated), NULL if empty
1027 * clientinlen -- length of initial response
1028 * serverout -- initial server challenge, NULL if done
1029 * (library handles freeing this string)
1030 * serveroutlen -- length of initial server challenge
1032 * pconn -- the connection negotiation state on success
1034 * Same returns as sasl_server_step() or
1035 * SASL_NOMECH if mechanism not available.
1037 LIBSASL_API int sasl_server_start(sasl_conn_t *conn,
1039 const char *clientin,
1040 unsigned clientinlen,
1041 const char **serverout,
1042 unsigned *serveroutlen);
1044 /* perform one step of the SASL exchange
1045 * inputlen & input -- client data
1046 * NULL on first step if no optional client step
1047 * outputlen & output -- set to the server data to transmit
1048 * to the client in the next step
1049 * (library handles freeing this)
1052 * SASL_OK -- exchange is complete.
1053 * SASL_CONTINUE -- indicates another step is necessary.
1054 * SASL_TRANS -- entry for user exists, but not for mechanism
1055 * and transition is possible
1056 * SASL_BADPARAM -- service name needed
1057 * SASL_BADPROT -- invalid input from client
1060 LIBSASL_API int sasl_server_step(sasl_conn_t *conn,
1061 const char *clientin,
1062 unsigned clientinlen,
1063 const char **serverout,
1064 unsigned *serveroutlen);
1066 /* check if an apop exchange is valid
1067 * (note this is an optional part of the SASL API)
1068 * if challenge is NULL, just check if APOP is enabled
1070 * challenge -- challenge which was sent to client
1071 * challen -- length of challenge, 0 = strlen(challenge)
1072 * response -- client response, "<user> <digest>" (RFC 1939)
1073 * resplen -- length of response, 0 = strlen(response)
1075 * SASL_OK -- success
1076 * SASL_BADAUTH -- authentication failed
1077 * SASL_BADPARAM -- missing challenge
1078 * SASL_BADPROT -- protocol error (e.g., response in wrong format)
1079 * SASL_NOVERIFY -- user found, but no verifier
1080 * SASL_NOMECH -- mechanism not supported
1081 * SASL_NOUSER -- user not found
1083 LIBSASL_API int sasl_checkapop(sasl_conn_t *conn,
1084 const char *challenge, unsigned challen,
1085 const char *response, unsigned resplen);
1087 /* check if a plaintext password is valid
1088 * if user is NULL, check if plaintext passwords are enabled
1090 * user -- user to query in current user_domain
1091 * userlen -- length of username, 0 = strlen(user)
1092 * pass -- plaintext password to check
1093 * passlen -- length of password, 0 = strlen(pass)
1095 * SASL_OK -- success
1096 * SASL_NOMECH -- mechanism not supported
1097 * SASL_NOVERIFY -- user found, but no verifier
1098 * SASL_NOUSER -- user not found
1100 LIBSASL_API int sasl_checkpass(sasl_conn_t *conn,
1101 const char *user, unsigned userlen,
1102 const char *pass, unsigned passlen);
1104 /* check if a user exists on server
1105 * conn -- connection context
1106 * service -- registered name of the service using SASL (e.g. "imap")
1107 * user_realm -- permits multiple user realms on server, NULL = default
1108 * user -- NUL terminated user name
1111 * SASL_OK -- success
1112 * SASL_DISABLED -- account disabled
1113 * SASL_NOUSER -- user not found
1114 * SASL_NOVERIFY -- user found, but no usable mechanism
1115 * SASL_NOMECH -- no mechanisms enabled
1117 LIBSASL_API int sasl_user_exists(sasl_conn_t *conn,
1118 const char *service,
1119 const char *user_realm,
1122 /* set the password for a user
1123 * conn -- SASL connection
1125 * pass -- plaintext password, may be NULL to remove user
1126 * passlen -- length of password, 0 = strlen(pass)
1127 * oldpass -- NULL will sometimes work
1128 * oldpasslen -- length of password, 0 = strlen(oldpass)
1129 * flags -- see flags below
1132 * SASL_NOCHANGE -- proper entry already exists
1133 * SASL_NOMECH -- no authdb supports password setting as configured
1134 * SASL_NOVERIFY -- user exists, but no settable password present
1135 * SASL_DISABLED -- account disabled
1136 * SASL_PWLOCK -- password locked
1137 * SASL_WEAKPASS -- password too weak for security policy
1138 * SASL_NOUSERPASS -- user-supplied passwords not permitted
1139 * SASL_FAIL -- OS error
1140 * SASL_BADPARAM -- password too long
1141 * SASL_OK -- successful
1143 LIBSASL_API int sasl_setpass(sasl_conn_t *conn,
1145 const char *pass, unsigned passlen,
1146 const char *oldpass, unsigned oldpasslen,
1148 #define SASL_SET_CREATE 0x01 /* create a new entry for user */
1149 #define SASL_SET_DISABLE 0x02 /* disable user account */
1150 #define SASL_SET_NOPLAIN 0x04 /* do not store secret in plain text */
1151 #define SASL_SET_CURMECH_ONLY 0x08 /* set the mechanism specific password only.
1152 fail if no current mechanism */
1154 /*********************************************************
1155 * Auxiliary Property Support -- added by cjn 1999-09-29 *
1156 *********************************************************/
1158 #define SASL_AUX_END NULL /* last auxiliary property */
1160 /* traditional Posix items (should be implemented on Posix systems) */
1161 #define SASL_AUX_PASSWORD_PROP "userPassword" /* User Password */
1162 #define SASL_AUX_PASSWORD "*" SASL_AUX_PASSWORD_PROP /* User Password (of authid) */
1163 #define SASL_AUX_UIDNUM "uidNumber" /* UID number for the user */
1164 #define SASL_AUX_GIDNUM "gidNumber" /* GID for the user */
1165 #define SASL_AUX_FULLNAME "gecos" /* full name of the user, unix-style */
1166 #define SASL_AUX_HOMEDIR "homeDirectory" /* home directory for user */
1167 #define SASL_AUX_SHELL "loginShell" /* login shell for the user */
1169 /* optional additional items (not necessarily implemented) */
1170 /* single preferred mail address for user canonically-quoted
1171 * RFC821/822 syntax */
1172 #define SASL_AUX_MAILADDR "mail"
1173 /* path to unix-style mailbox for user */
1174 #define SASL_AUX_UNIXMBX "mailMessageStore"
1175 /* SMTP mail channel name to use if user authenticates successfully */
1176 #define SASL_AUX_MAILCHAN "mailSMTPSubmitChannel"
1178 /* Request a set of auxiliary properties
1179 * conn connection context
1180 * propnames list of auxiliary property names to request ending with
1183 * Subsequent calls will add items to the request list. Call with NULL
1184 * to clear the request list.
1187 * SASL_OK -- success
1188 * SASL_BADPARAM -- bad count/conn parameter
1189 * SASL_NOMEM -- out of memory
1191 LIBSASL_API int sasl_auxprop_request(sasl_conn_t *conn,
1192 const char **propnames);
1194 /* Returns current auxiliary property context.
1195 * Use functions in prop.h to access content
1197 * if authentication hasn't completed, property values may be empty/NULL
1199 * properties not recognized by active plug-ins will be left empty/NULL
1201 * returns NULL if conn is invalid.
1203 LIBSASL_API struct propctx *sasl_auxprop_getctx(sasl_conn_t *conn);
1205 /* Store the set of auxiliary properties for the given user.
1206 * Use functions in prop.h to set the content.
1208 * conn connection context
1209 * ctx property context from prop_new()/prop_request()/prop_set()
1210 * user NUL terminated user
1212 * Call with NULL 'ctx' to see if the backend allows storing properties.
1215 * SASL_OK -- success
1216 * SASL_NOMECH -- can not store some/all properties
1217 * SASL_BADPARAM -- bad conn/ctx/user parameter
1218 * SASL_NOMEM -- out of memory
1219 * SASL_FAIL -- failed to store
1221 LIBSASL_API int sasl_auxprop_store(sasl_conn_t *conn,
1222 struct propctx *ctx, const char *user);
1224 /**********************
1225 * security layer API *
1226 **********************/
1228 /* encode a block of data for transmission using security layer,
1229 * returning the input buffer if there is no security layer.
1230 * output is only valid until next call to sasl_encode or sasl_encodev
1232 * SASL_OK -- success (returns input if no layer negotiated)
1233 * SASL_NOTDONE -- security layer negotiation not finished
1234 * SASL_BADPARAM -- inputlen is greater than the SASL_MAXOUTBUF
1236 LIBSASL_API int sasl_encode(sasl_conn_t *conn,
1237 const char *input, unsigned inputlen,
1238 const char **output, unsigned *outputlen);
1240 /* encode a block of data for transmission using security layer
1241 * output is only valid until next call to sasl_encode or sasl_encodev
1243 * SASL_OK -- success (returns input if no layer negotiated)
1244 * SASL_NOTDONE -- security layer negotiation not finished
1245 * SASL_BADPARAM -- input length is greater than the SASL_MAXOUTBUF
1246 * or no security layer
1248 LIBSASL_API int sasl_encodev(sasl_conn_t *conn,
1249 const struct iovec *invec, unsigned numiov,
1250 const char **output, unsigned *outputlen);
1252 /* decode a block of data received using security layer
1253 * returning the input buffer if there is no security layer.
1254 * output is only valid until next call to sasl_decode
1256 * if outputlen is 0 on return, than the value of output is undefined.
1259 * SASL_OK -- success (returns input if no layer negotiated)
1260 * SASL_NOTDONE -- security layer negotiation not finished
1261 * SASL_BADMAC -- bad message integrity check
1263 LIBSASL_API int sasl_decode(sasl_conn_t *conn,
1264 const char *input, unsigned inputlen,
1265 const char **output, unsigned *outputlen);