sasl.h 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  1. /* This is a proposed C API for support of SASL
  2. *
  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*******************************
  9. *
  10. * Basic Type Summary:
  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
  18. *
  19. * Callbacks:
  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
  25. *
  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
  32. *
  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
  42. *
  43. * Utility functions:
  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
  47. *
  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
  53. *
  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
  68. *
  69. * Basic client model:
  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
  87. *
  88. * Basic Server model:
  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
  102. *
  103. *************************************************
  104. * IMPORTANT NOTE: server realms / username syntax
  105. *
  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 "@".
  116. *
  117. * If the server forbids the use of "@" in user names for other
  118. * purposes, this simplifies security validation.
  119. */
  120. #ifndef SASL_H
  121. #define SASL_H 1
  122. #include <stddef.h> /* For size_t */
  123. /* Keep in sync with win32/common.mak */
  124. #define SASL_VERSION_MAJOR 2
  125. #define SASL_VERSION_MINOR 1
  126. #define SASL_VERSION_STEP 28
  127. /* A convenience macro: same as was defined in the OpenLDAP LDAPDB */
  128. #define SASL_VERSION_FULL ((SASL_VERSION_MAJOR << 16) |\
  129. (SASL_VERSION_MINOR << 8) | SASL_VERSION_STEP)
  130. #include "prop.h"
  131. /*************
  132. * Basic API *
  133. *************/
  134. /* SASL result codes: */
  135. #define SASL_CONTINUE 1 /* another step is needed in authentication */
  136. #define SASL_OK 0 /* successful result */
  137. #define SASL_FAIL -1 /* generic failure */
  138. #define SASL_NOMEM -2 /* memory shortage failure */
  139. #define SASL_BUFOVER -3 /* overflowed buffer */
  140. #define SASL_NOMECH -4 /* mechanism not supported */
  141. #define SASL_BADPROT -5 /* bad protocol / cancel */
  142. #define SASL_NOTDONE -6 /* can't request info until later in exchange */
  143. #define SASL_BADPARAM -7 /* invalid parameter supplied */
  144. #define SASL_TRYAGAIN -8 /* transient failure (e.g., weak key) */
  145. #define SASL_BADMAC -9 /* integrity check failed */
  146. #define SASL_NOTINIT -12 /* SASL library not initialized */
  147. /* -- client only codes -- */
  148. #define SASL_INTERACT 2 /* needs user interaction */
  149. #define SASL_BADSERV -10 /* server failed mutual authentication step */
  150. #define SASL_WRONGMECH -11 /* mechanism doesn't support requested feature */
  151. /* -- server only codes -- */
  152. #define SASL_BADAUTH -13 /* authentication failure */
  153. #define SASL_NOAUTHZ -14 /* authorization failure */
  154. #define SASL_TOOWEAK -15 /* mechanism too weak for this user */
  155. #define SASL_ENCRYPT -16 /* encryption needed to use mechanism */
  156. #define SASL_TRANS -17 /* One time use of a plaintext password will
  157. enable requested mechanism for user */
  158. #define SASL_EXPIRED -18 /* passphrase expired, has to be reset */
  159. #define SASL_DISABLED -19 /* account disabled */
  160. #define SASL_NOUSER -20 /* user not found */
  161. #define SASL_BADVERS -23 /* version mismatch with plug-in */
  162. #define SASL_UNAVAIL -24 /* remote authentication server unavailable */
  163. #define SASL_NOVERIFY -26 /* user exists, but no verifier for user */
  164. /* -- codes for password setting -- */
  165. #define SASL_PWLOCK -21 /* passphrase locked */
  166. #define SASL_NOCHANGE -22 /* requested change was not needed */
  167. #define SASL_WEAKPASS -27 /* passphrase is too weak for security policy */
  168. #define SASL_NOUSERPASS -28 /* user supplied passwords not permitted */
  169. #define SASL_NEED_OLD_PASSWD -29 /* sasl_setpass needs old password in order
  170. to perform password change */
  171. #define SASL_CONSTRAINT_VIOLAT -30 /* a property can't be stored,
  172. because of some constrains/policy violation */
  173. #define SASL_BADBINDING -32 /* channel binding failure */
  174. #define SASL_CONFIGERR -100 /* error when parsing configuration file */
  175. /* max size of a sasl mechanism name */
  176. #define SASL_MECHNAMEMAX 20
  177. #ifdef _WIN32
  178. /* Define to have the same layout as a WSABUF */
  179. #ifndef STRUCT_IOVEC_DEFINED
  180. #define STRUCT_IOVEC_DEFINED 1
  181. struct iovec {
  182. long iov_len;
  183. char *iov_base;
  184. };
  185. #endif
  186. #else
  187. struct iovec; /* Defined in OS headers */
  188. #endif
  189. /* per-connection SASL negotiation state for client or server
  190. */
  191. typedef struct sasl_conn sasl_conn_t;
  192. /* Plain text password structure.
  193. * len is the length of the password, data is the text.
  194. */
  195. typedef struct sasl_secret {
  196. unsigned long len;
  197. unsigned char data[1]; /* variable sized */
  198. } sasl_secret_t;
  199. /* random data context structure
  200. */
  201. typedef struct sasl_rand_s sasl_rand_t;
  202. #ifdef __cplusplus
  203. extern "C" {
  204. #endif
  205. /****************************
  206. * Configure Basic Services *
  207. ****************************/
  208. /* the following functions are used to adjust how allocation and mutexes work
  209. * they must be called before all other SASL functions:
  210. */
  211. #include <sys/types.h>
  212. /* memory allocation functions which may optionally be replaced:
  213. */
  214. typedef void *sasl_malloc_t(size_t);
  215. typedef void *sasl_calloc_t(size_t, size_t);
  216. typedef void *sasl_realloc_t(void *, size_t);
  217. typedef void sasl_free_t(void *);
  218. LIBSASL_API void sasl_set_alloc(sasl_malloc_t *,
  219. sasl_calloc_t *,
  220. sasl_realloc_t *,
  221. sasl_free_t *);
  222. /* mutex functions which may optionally be replaced:
  223. * sasl_mutex_alloc allocates a mutex structure
  224. * sasl_mutex_lock blocks until mutex locked
  225. * returns -1 on deadlock or parameter error
  226. * returns 0 on success
  227. * sasl_mutex_unlock unlocks mutex if it's locked
  228. * returns -1 if not locked or parameter error
  229. * returns 0 on success
  230. * sasl_mutex_free frees a mutex structure
  231. */
  232. typedef void *sasl_mutex_alloc_t(void);
  233. typedef int sasl_mutex_lock_t(void *mutex);
  234. typedef int sasl_mutex_unlock_t(void *mutex);
  235. typedef void sasl_mutex_free_t(void *mutex);
  236. LIBSASL_API void sasl_set_mutex(sasl_mutex_alloc_t *, sasl_mutex_lock_t *,
  237. sasl_mutex_unlock_t *, sasl_mutex_free_t *);
  238. /*****************************
  239. * Security preference types *
  240. *****************************/
  241. /* security layer strength factor -- an unsigned integer usable by the caller
  242. * to specify approximate security layer strength desired. Roughly
  243. * correlated to effective key length for encryption.
  244. * 0 = no protection
  245. * 1 = integrity protection only
  246. * 40 = 40-bit DES or 40-bit RC2/RC4
  247. * 56 = DES
  248. * 112 = triple-DES
  249. * 128 = 128-bit RC2/RC4/BLOWFISH
  250. * 256 = baseline AES
  251. */
  252. typedef unsigned sasl_ssf_t;
  253. /* usage flags provided to sasl_server_new and sasl_client_new:
  254. */
  255. #define SASL_SUCCESS_DATA 0x0004 /* server supports data on success */
  256. #define SASL_NEED_PROXY 0x0008 /* require a mech that allows proxying */
  257. #define SASL_NEED_HTTP 0x0010 /* require a mech that can do HTTP auth */
  258. /***************************
  259. * Security Property Types *
  260. ***************************/
  261. /* Structure specifying the client or server's security policy
  262. * and optional additional properties.
  263. */
  264. /* These are the various security flags apps can specify. */
  265. /* NOPLAINTEXT -- don't permit mechanisms susceptible to simple
  266. * passive attack (e.g., PLAIN, LOGIN)
  267. * NOACTIVE -- protection from active (non-dictionary) attacks
  268. * during authentication exchange.
  269. * Authenticates server.
  270. * NODICTIONARY -- don't permit mechanisms susceptible to passive
  271. * dictionary attack
  272. * FORWARD_SECRECY -- require forward secrecy between sessions
  273. * (breaking one won't help break next)
  274. * NOANONYMOUS -- don't permit mechanisms that allow anonymous login
  275. * PASS_CREDENTIALS -- require mechanisms which pass client
  276. * credentials, and allow mechanisms which can pass
  277. * credentials to do so
  278. * MUTUAL_AUTH -- require mechanisms which provide mutual
  279. * authentication
  280. */
  281. #define SASL_SEC_NOPLAINTEXT 0x0001
  282. #define SASL_SEC_NOACTIVE 0x0002
  283. #define SASL_SEC_NODICTIONARY 0x0004
  284. #define SASL_SEC_FORWARD_SECRECY 0x0008
  285. #define SASL_SEC_NOANONYMOUS 0x0010
  286. #define SASL_SEC_PASS_CREDENTIALS 0x0020
  287. #define SASL_SEC_MUTUAL_AUTH 0x0040
  288. #define SASL_SEC_MAXIMUM 0xFFFF
  289. /* This is used when adding hash size to the security_flags field */
  290. /* NB: hash size is in bits */
  291. #define SASL_SET_HASH_STRENGTH_BITS(x) (((x) / 8) << 16)
  292. /* NB: This value is in bytes */
  293. #define SASL_GET_HASH_STRENGTH(x) ((x) >> 16)
  294. typedef struct sasl_security_properties
  295. {
  296. /* security strength factor
  297. * min_ssf = minimum acceptable final level
  298. * max_ssf = maximum acceptable final level
  299. */
  300. sasl_ssf_t min_ssf;
  301. sasl_ssf_t max_ssf;
  302. /* Maximum security layer receive buffer size.
  303. * 0=security layer not supported
  304. */
  305. unsigned maxbufsize;
  306. /* bitfield for attacks to protect against */
  307. unsigned security_flags;
  308. /* NULL terminated array of additional property names, values */
  309. const char **property_names;
  310. const char **property_values;
  311. } sasl_security_properties_t;
  312. /******************
  313. * Callback types *
  314. ******************/
  315. /*
  316. * Extensible type for a client/server callbacks
  317. * id -- identifies callback type
  318. * proc -- procedure call arguments vary based on id
  319. * context -- context passed to procedure
  320. */
  321. /* Note that any memory that is allocated by the callback needs to be
  322. * freed by the application, be it via function call or interaction.
  323. *
  324. * It may be freed after sasl_*_step returns SASL_OK. if the mechanism
  325. * requires this information to persist (for a security layer, for example)
  326. * it must maintain a private copy.
  327. */
  328. typedef struct sasl_callback {
  329. /* Identifies the type of the callback function.
  330. * Mechanisms must ignore callbacks with id's they don't recognize.
  331. */
  332. unsigned long id;
  333. int (*proc)(void); /* Callback function. Types of arguments vary by 'id' */
  334. void *context;
  335. } sasl_callback_t;
  336. /* callback ids & functions:
  337. */
  338. #define SASL_CB_LIST_END 0 /* end of list */
  339. /* option reading callback -- this allows a SASL configuration to be
  340. * encapsulated in the caller's configuration system. Some implementations
  341. * may use default config file(s) if this is omitted. Configuration items
  342. * may be plugin-specific and are arbitrary strings.
  343. *
  344. * inputs:
  345. * context -- option context from callback record
  346. * plugin_name -- name of plugin (NULL = general SASL option)
  347. * option -- name of option
  348. * output:
  349. * result -- set to result which persists until next getopt in
  350. * same thread, unchanged if option not found
  351. * len -- length of result (may be NULL)
  352. * returns:
  353. * SASL_OK -- no error
  354. * SASL_FAIL -- error
  355. */
  356. typedef int sasl_getopt_t(void *context, const char *plugin_name,
  357. const char *option,
  358. const char **result, unsigned *len);
  359. #define SASL_CB_GETOPT 1
  360. /* Logging levels for use with the logging callback function. */
  361. #define SASL_LOG_NONE 0 /* don't log anything */
  362. #define SASL_LOG_ERR 1 /* log unusual errors (default) */
  363. #define SASL_LOG_FAIL 2 /* log all authentication failures */
  364. #define SASL_LOG_WARN 3 /* log non-fatal warnings */
  365. #define SASL_LOG_NOTE 4 /* more verbose than LOG_WARN */
  366. #define SASL_LOG_DEBUG 5 /* more verbose than LOG_NOTE */
  367. #define SASL_LOG_TRACE 6 /* traces of internal protocols */
  368. #define SASL_LOG_PASS 7 /* traces of internal protocols, including
  369. * passwords */
  370. /* logging callback -- this allows plugins and the middleware to
  371. * log operations they perform.
  372. * inputs:
  373. * context -- logging context from the callback record
  374. * level -- logging level; see above
  375. * message -- message to log
  376. * returns:
  377. * SASL_OK -- no error
  378. * SASL_FAIL -- error
  379. */
  380. typedef int sasl_log_t(void *context,
  381. int level,
  382. const char *message);
  383. #define SASL_CB_LOG 2
  384. /* getpath callback -- this allows applications to specify the
  385. * colon-separated path to search for plugins (by default,
  386. * taken from an implementation-specific location).
  387. * inputs:
  388. * context -- getpath context from the callback record
  389. * outputs:
  390. * path -- colon seperated path
  391. * returns:
  392. * SASL_OK -- no error
  393. * SASL_FAIL -- error
  394. */
  395. typedef int sasl_getpath_t(void *context,
  396. const char **path);
  397. #define SASL_CB_GETPATH 3
  398. /* verify file callback -- this allows applications to check if they
  399. * want SASL to use files, file by file. This is intended to allow
  400. * applications to sanity check the environment to make sure plugins
  401. * or the configuration file can't be written to, etc.
  402. * inputs:
  403. * context -- verifypath context from the callback record
  404. * file -- full path to file to verify
  405. * type -- type of file to verify (see below)
  406. * returns:
  407. * SASL_OK -- no error (file can safely be used)
  408. * SASL_CONTINUE -- continue WITHOUT using this file
  409. * SASL_FAIL -- error
  410. */
  411. /* these are the types of files libsasl will ask about */
  412. typedef enum {
  413. SASL_VRFY_PLUGIN=0, /* a DLL/shared library plug-in */
  414. SASL_VRFY_CONF=1, /* a configuration file */
  415. SASL_VRFY_PASSWD=2, /* a password storage file/db */
  416. SASL_VRFY_OTHER=3 /* some other file */
  417. } sasl_verify_type_t;
  418. typedef int sasl_verifyfile_t(void *context,
  419. const char *file, sasl_verify_type_t type);
  420. #define SASL_CB_VERIFYFILE 4
  421. /* getconfpath callback -- this allows applications to specify the
  422. * colon-separated path to search for config files (by default,
  423. * taken from the SASL_CONF_PATH environment variable).
  424. * inputs:
  425. * context -- getconfpath context from the callback record
  426. * outputs:
  427. * path -- colon seperated path (allocated on the heap; the
  428. * library will free it using the sasl_free_t *
  429. * passed to sasl_set_callback, or the standard free()
  430. * library call).
  431. * returns:
  432. * SASL_OK -- no error
  433. * SASL_FAIL -- error
  434. */
  435. typedef int sasl_getconfpath_t(void *context,
  436. char **path);
  437. #define SASL_CB_GETCONFPATH 5
  438. /* client/user interaction callbacks:
  439. */
  440. /* Simple prompt -- result must persist until next call to getsimple on
  441. * same connection or until connection context is disposed
  442. * inputs:
  443. * context -- context from callback structure
  444. * id -- callback id
  445. * outputs:
  446. * result -- set to NUL terminated string
  447. * NULL = user cancel
  448. * len -- length of result
  449. * returns SASL_OK
  450. */
  451. typedef int sasl_getsimple_t(void *context, int id,
  452. const char **result, unsigned *len);
  453. #define SASL_CB_USER 0x4001 /* client user identity to login as */
  454. #define SASL_CB_AUTHNAME 0x4002 /* client authentication name */
  455. #define SASL_CB_LANGUAGE 0x4003 /* comma separated list of RFC 1766
  456. * language codes in order of preference
  457. * to be used to localize client prompts
  458. * or server error codes */
  459. #define SASL_CB_CNONCE 0x4007 /* caller supplies client-nonce
  460. * primarily for testing purposes */
  461. /* get a sasl_secret_t (plaintext password with length)
  462. * inputs:
  463. * conn -- connection context
  464. * context -- context from callback structure
  465. * id -- callback id
  466. * outputs:
  467. * psecret -- set to NULL to cancel
  468. * set to password structure which must persist until
  469. * next call to getsecret in same connection, but middleware
  470. * will erase password data when it's done with it.
  471. * returns SASL_OK
  472. */
  473. typedef int sasl_getsecret_t(sasl_conn_t *conn, void *context, int id,
  474. sasl_secret_t **psecret);
  475. #define SASL_CB_PASS 0x4004 /* client passphrase-based secret */
  476. /* prompt for input in response to a challenge.
  477. * input:
  478. * context -- context from callback structure
  479. * id -- callback id
  480. * challenge -- server challenge
  481. * output:
  482. * result -- NUL terminated result, NULL = user cancel
  483. * len -- length of result
  484. * returns SASL_OK
  485. */
  486. typedef int sasl_chalprompt_t(void *context, int id,
  487. const char *challenge,
  488. const char *prompt, const char *defresult,
  489. const char **result, unsigned *len);
  490. #define SASL_CB_ECHOPROMPT 0x4005 /* challenge and client enterred result */
  491. #define SASL_CB_NOECHOPROMPT 0x4006 /* challenge and client enterred result */
  492. /* prompt (or autoselect) the realm to do authentication in.
  493. * may get a list of valid realms.
  494. * input:
  495. * context -- context from callback structure
  496. * id -- callback id
  497. * availrealms -- available realms; string list; NULL terminated
  498. * list may be empty.
  499. * output:
  500. * result -- NUL terminated realm; NULL is equivalent to ""
  501. * returns SASL_OK
  502. * result must persist until the next callback
  503. */
  504. typedef int sasl_getrealm_t(void *context, int id,
  505. const char **availrealms,
  506. const char **result);
  507. #define SASL_CB_GETREALM (0x4008) /* realm to attempt authentication in */
  508. /* server callbacks:
  509. */
  510. /* improved callback to verify authorization;
  511. * canonicalization now handled elsewhere
  512. * conn -- connection context
  513. * requested_user -- the identity/username to authorize (NUL terminated)
  514. * rlen -- length of requested_user
  515. * auth_identity -- the identity associated with the secret (NUL terminated)
  516. * alen -- length of auth_identity
  517. * default_realm -- default user realm, as passed to sasl_server_new if
  518. * urlen -- length of default realm
  519. * propctx -- auxiliary properties
  520. * returns SASL_OK on success,
  521. * SASL_NOAUTHZ or other SASL response on failure
  522. */
  523. typedef int sasl_authorize_t(sasl_conn_t *conn,
  524. void *context,
  525. const char *requested_user, unsigned rlen,
  526. const char *auth_identity, unsigned alen,
  527. const char *def_realm, unsigned urlen,
  528. struct propctx *propctx);
  529. #define SASL_CB_PROXY_POLICY 0x8001
  530. /* functions for "userdb" based plugins to call to get/set passwords.
  531. * the location for the passwords is determined by the caller or middleware.
  532. * plug-ins may get passwords from other locations.
  533. */
  534. /* callback to verify a plaintext password against the caller-supplied
  535. * user database. This is necessary to allow additional <method>s for
  536. * encoding of the userPassword property.
  537. * user -- NUL terminated user name with user@realm syntax
  538. * pass -- password to check (may not be NUL terminated)
  539. * passlen -- length of password to check
  540. * propctx -- auxiliary properties for user
  541. */
  542. typedef int sasl_server_userdb_checkpass_t(sasl_conn_t *conn,
  543. void *context,
  544. const char *user,
  545. const char *pass,
  546. unsigned passlen,
  547. struct propctx *propctx);
  548. #define SASL_CB_SERVER_USERDB_CHECKPASS (0x8005)
  549. /* callback to store/change a plaintext password in the user database
  550. * user -- NUL terminated user name with user@realm syntax
  551. * pass -- password to store (may not be NUL terminated)
  552. * passlen -- length of password to store
  553. * propctx -- auxiliary properties (not stored)
  554. * flags -- see SASL_SET_* flags below (SASL_SET_CREATE optional)
  555. */
  556. typedef int sasl_server_userdb_setpass_t(sasl_conn_t *conn,
  557. void *context,
  558. const char *user,
  559. const char *pass,
  560. unsigned passlen,
  561. struct propctx *propctx,
  562. unsigned flags);
  563. #define SASL_CB_SERVER_USERDB_SETPASS (0x8006)
  564. /* callback for a server-supplied user canonicalization function.
  565. *
  566. * This function is called directly after the mechanism has the
  567. * authentication and authorization IDs. It is called before any
  568. * User Canonicalization plugin is called. It has the responsibility
  569. * of copying its output into the provided output buffers.
  570. *
  571. * in, inlen -- user name to canonicalize, may not be NUL terminated
  572. * may be same buffer as out
  573. * flags -- not currently used, supplied by auth mechanism
  574. * user_realm -- the user realm (may be NULL in case of client)
  575. * out -- buffer to copy user name
  576. * out_max -- max length of user name
  577. * out_len -- set to length of user name
  578. *
  579. * returns
  580. * SASL_OK on success
  581. * SASL_BADPROT username contains invalid character
  582. */
  583. /* User Canonicalization Function Flags */
  584. #define SASL_CU_NONE 0x00 /* Not a valid flag to pass */
  585. /* One of the following two is required */
  586. #define SASL_CU_AUTHID 0x01
  587. #define SASL_CU_AUTHZID 0x02
  588. /* Combine the following with SASL_CU_AUTHID, if you don't want
  589. to fail if auxprop returned SASL_NOUSER/SASL_NOMECH. */
  590. #define SASL_CU_EXTERNALLY_VERIFIED 0x04
  591. #define SASL_CU_OVERRIDE 0x08 /* mapped to SASL_AUXPROP_OVERRIDE */
  592. /* The following CU flags are passed "as is" down to auxprop lookup */
  593. #define SASL_CU_ASIS_MASK 0xFFF0
  594. /* NOTE: Keep in sync with SASL_AUXPROP_<XXX> flags */
  595. #define SASL_CU_VERIFY_AGAINST_HASH 0x10
  596. typedef int sasl_canon_user_t(sasl_conn_t *conn,
  597. void *context,
  598. const char *in, unsigned inlen,
  599. unsigned flags,
  600. const char *user_realm,
  601. char *out,
  602. unsigned out_max, unsigned *out_len);
  603. #define SASL_CB_CANON_USER (0x8007)
  604. /**********************************
  605. * Common Client/server functions *
  606. **********************************/
  607. /* Types of paths to set (see sasl_set_path below). */
  608. #define SASL_PATH_TYPE_PLUGIN 0
  609. #define SASL_PATH_TYPE_CONFIG 1
  610. /* a simpler way to set plugin path or configuration file path
  611. * without the need to set sasl_getpath_t callback.
  612. *
  613. * This function can be called before sasl_server_init/sasl_client_init.
  614. */
  615. LIBSASL_API int sasl_set_path (int path_type, char * path);
  616. /* get sasl library version information
  617. * implementation is a vendor-defined string
  618. * version is a vender-defined representation of the version #.
  619. *
  620. * This function is being deprecated in favor of sasl_version_info. */
  621. LIBSASL_API void sasl_version(const char **implementation,
  622. int *version);
  623. /* Extended version of sasl_version().
  624. *
  625. * This function is to be used
  626. * for library version display and logging
  627. * for bug workarounds in old library versions
  628. *
  629. * The sasl_version_info is not to be used for API feature detection.
  630. *
  631. * All parameters are optional. If NULL is specified, the value is not returned.
  632. */
  633. LIBSASL_API void sasl_version_info (const char **implementation,
  634. const char **version_string,
  635. int *version_major,
  636. int *version_minor,
  637. int *version_step,
  638. int *version_patch);
  639. /* dispose of all SASL plugins. Connection
  640. * states have to be disposed of before calling this.
  641. *
  642. * This function is DEPRECATED in favour of sasl_server_done/
  643. * sasl_client_done.
  644. */
  645. LIBSASL_API void sasl_done(void);
  646. /* dispose of all SASL plugins. Connection
  647. * states have to be disposed of before calling this.
  648. * This function should be called instead of sasl_done(),
  649. whenever possible.
  650. */
  651. LIBSASL_API int sasl_server_done(void);
  652. /* dispose of all SASL plugins. Connection
  653. * states have to be disposed of before calling this.
  654. * This function should be called instead of sasl_done(),
  655. whenever possible.
  656. */
  657. LIBSASL_API int sasl_client_done(void);
  658. /* dispose connection state, sets it to NULL
  659. * checks for pointer to NULL
  660. */
  661. LIBSASL_API void sasl_dispose(sasl_conn_t **pconn);
  662. /* translate an error number into a string
  663. * input:
  664. * saslerr -- the error number
  665. * langlist -- comma separated list of RFC 1766 languages (may be NULL)
  666. * results:
  667. * outlang -- the language actually used (may be NULL if don't care)
  668. * returns:
  669. * the error message in UTF-8 (only the US-ASCII subset if langlist is NULL)
  670. */
  671. LIBSASL_API const char *sasl_errstring(int saslerr,
  672. const char *langlist,
  673. const char **outlang);
  674. /* get detail about the last error that occurred on a connection
  675. * text is sanitized so it's suitable to send over the wire
  676. * (e.g., no distinction between SASL_BADAUTH and SASL_NOUSER)
  677. * input:
  678. * conn -- mandatory connection context
  679. * returns:
  680. * the error message in UTF-8 (only the US-ASCII subset permitted if no
  681. * SASL_CB_LANGUAGE callback is present)
  682. */
  683. LIBSASL_API const char *sasl_errdetail(sasl_conn_t *conn);
  684. /* set the error string which will be returned by sasl_errdetail() using
  685. * syslog()-style formatting (e.g. printf-style with %m as most recent
  686. * errno error)
  687. *
  688. * primarily for use by server callbacks such as the sasl_authorize_t
  689. * callback and internally to plug-ins
  690. *
  691. * This will also trigger a call to the SASL logging callback (if any)
  692. * with a level of SASL_LOG_FAIL unless the SASL_NOLOG flag is set.
  693. *
  694. * Messages should be sensitive to the current language setting. If there
  695. * is no SASL_CB_LANGUAGE callback messages MUST be US-ASCII otherwise UTF-8
  696. * is used and use of RFC 2482 for mixed-language text is encouraged.
  697. *
  698. * if conn is NULL, function does nothing
  699. */
  700. LIBSASL_API void sasl_seterror(sasl_conn_t *conn, unsigned flags,
  701. const char *fmt, ...);
  702. #define SASL_NOLOG 0x01
  703. /* get property from SASL connection state
  704. * propnum -- property number
  705. * pvalue -- pointer to value
  706. * returns:
  707. * SASL_OK -- no error
  708. * SASL_NOTDONE -- property not available yet
  709. * SASL_BADPARAM -- bad property number
  710. */
  711. LIBSASL_API int sasl_getprop(sasl_conn_t *conn, int propnum,
  712. const void **pvalue);
  713. #define SASL_USERNAME 0 /* pointer to NUL terminated user name */
  714. #define SASL_SSF 1 /* security layer security strength factor,
  715. * if 0, call to sasl_encode, sasl_decode
  716. * unnecessary */
  717. #define SASL_MAXOUTBUF 2 /* security layer max output buf unsigned */
  718. #define SASL_DEFUSERREALM 3 /* default realm passed to server_new */
  719. /* or set with setprop */
  720. #define SASL_GETOPTCTX 4 /* context for getopt callback */
  721. #define SASL_CALLBACK 7 /* current callback function list */
  722. #define SASL_IPLOCALPORT 8 /* iplocalport string passed to server_new */
  723. #define SASL_IPREMOTEPORT 9 /* ipremoteport string passed to server_new */
  724. /* This returns a string which is either empty or has an error message
  725. * from sasl_seterror (e.g., from a plug-in or callback). It differs
  726. * from the result of sasl_errdetail() which also takes into account the
  727. * last return status code.
  728. */
  729. #define SASL_PLUGERR 10
  730. /* a handle to any delegated credentials or NULL if none is present
  731. * is returned by the mechanism. The user will probably need to know
  732. * which mechanism was used to actually known how to make use of them
  733. * currently only implemented for the gssapi mechanism */
  734. #define SASL_DELEGATEDCREDS 11
  735. #define SASL_SERVICE 12 /* service passed to sasl_*_new */
  736. #define SASL_SERVERFQDN 13 /* serverFQDN passed to sasl_*_new */
  737. #define SASL_AUTHSOURCE 14 /* name of auth source last used, useful
  738. * for failed authentication tracking */
  739. #define SASL_MECHNAME 15 /* active mechanism name, if any */
  740. #define SASL_AUTHUSER 16 /* authentication/admin user */
  741. #define SASL_APPNAME 17 /* application name (used for logging/
  742. configuration), same as appname parameter
  743. to sasl_server_init */
  744. /* GSS-API credential handle for sasl_client_step() or sasl_server_step().
  745. * The application is responsible for releasing this credential handle. */
  746. #define SASL_GSS_CREDS 18
  747. /* GSS name (gss_name_t) of the peer, as output by gss_inquire_context()
  748. * or gss_accept_sec_context().
  749. * On server end this is similar to SASL_USERNAME, but the gss_name_t
  750. * structure can contain additional attributes associated with the peer.
  751. */
  752. #define SASL_GSS_PEER_NAME 19
  753. /* Local GSS name (gss_name_t) as output by gss_inquire_context(). This
  754. * is particularly useful for servers that respond to multiple names. */
  755. #define SASL_GSS_LOCAL_NAME 20
  756. /* Channel binding information. Memory is managed by the caller. */
  757. typedef struct sasl_channel_binding {
  758. const char *name;
  759. int critical;
  760. unsigned long len;
  761. const unsigned char *data;
  762. } sasl_channel_binding_t;
  763. #define SASL_CHANNEL_BINDING 21
  764. /* HTTP Request (RFC 2616) - ONLY used for HTTP Digest Auth (RFC 2617) */
  765. typedef struct sasl_http_request {
  766. const char *method; /* HTTP Method */
  767. const char *uri; /* request-URI */
  768. const unsigned char *entity; /* entity-body */
  769. unsigned long elen; /* entity-body length */
  770. unsigned non_persist; /* Is it a non-persistent connection? */
  771. } sasl_http_request_t;
  772. #define SASL_HTTP_REQUEST 22
  773. /* set property in SASL connection state
  774. * returns:
  775. * SASL_OK -- value set
  776. * SASL_BADPARAM -- invalid property or value
  777. */
  778. LIBSASL_API int sasl_setprop(sasl_conn_t *conn,
  779. int propnum,
  780. const void *value);
  781. #define SASL_SSF_EXTERNAL 100 /* external SSF active (sasl_ssf_t *) */
  782. #define SASL_SEC_PROPS 101 /* sasl_security_properties_t */
  783. #define SASL_AUTH_EXTERNAL 102 /* external authentication ID (const char *) */
  784. /* If the SASL_AUTH_EXTERNAL value is non-NULL, then a special version of the
  785. * EXTERNAL mechanism is enabled (one for server-embedded EXTERNAL mechanisms).
  786. * Otherwise, the EXTERNAL mechanism will be absent unless a plug-in
  787. * including EXTERNAL is present.
  788. */
  789. /* do precalculations during an idle period or network round trip
  790. * may pass NULL to precompute for some mechanisms prior to connect
  791. * returns 1 if action taken, 0 if no action taken
  792. */
  793. LIBSASL_API int sasl_idle(sasl_conn_t *conn);
  794. /**************
  795. * Client API *
  796. **************/
  797. /* list of client interactions with user for caller to fill in
  798. */
  799. typedef struct sasl_interact {
  800. unsigned long id; /* same as client/user callback ID */
  801. const char *challenge; /* presented to user (e.g. OTP challenge) */
  802. const char *prompt; /* presented to user (e.g. "Username: ") */
  803. const char *defresult; /* default result string */
  804. const void *result; /* set to point to result */
  805. unsigned len; /* set to length of result */
  806. } sasl_interact_t;
  807. /* initialize the SASL client drivers
  808. * callbacks -- base callbacks for all client connections;
  809. * must include getopt callback
  810. * returns:
  811. * SASL_OK -- Success
  812. * SASL_NOMEM -- Not enough memory
  813. * SASL_BADVERS -- Mechanism version mismatch
  814. * SASL_BADPARAM -- missing getopt callback or error in config file
  815. * SASL_NOMECH -- No mechanisms available
  816. * ...
  817. */
  818. LIBSASL_API int sasl_client_init(const sasl_callback_t *callbacks);
  819. /* initialize a client exchange based on the specified mechanism
  820. * service -- registered name of the service using SASL (e.g. "imap")
  821. * serverFQDN -- the fully qualified domain name of the server
  822. * iplocalport -- client IPv4/IPv6 domain literal string with port
  823. * (if NULL, then mechanisms requiring IPaddr are disabled)
  824. * ipremoteport -- server IPv4/IPv6 domain literal string with port
  825. * (if NULL, then mechanisms requiring IPaddr are disabled)
  826. * prompt_supp -- list of client interactions supported
  827. * may also include sasl_getopt_t context & call
  828. * NULL prompt_supp = user/pass via SASL_INTERACT only
  829. * NULL proc = interaction supported via SASL_INTERACT
  830. * flags -- server usage flags (see above)
  831. * in/out:
  832. * pconn -- connection negotiation structure
  833. * pointer to NULL => allocate new
  834. *
  835. * Returns:
  836. * SASL_OK -- success
  837. * SASL_NOMECH -- no mechanism meets requested properties
  838. * SASL_NOMEM -- not enough memory
  839. */
  840. LIBSASL_API int sasl_client_new(const char *service,
  841. const char *serverFQDN,
  842. const char *iplocalport,
  843. const char *ipremoteport,
  844. const sasl_callback_t *prompt_supp,
  845. unsigned flags,
  846. sasl_conn_t **pconn);
  847. /* select a mechanism for a connection
  848. * mechlist -- mechanisms server has available (punctuation ignored)
  849. * if NULL, then discard cached info and retry last mech
  850. * output:
  851. * prompt_need -- on SASL_INTERACT, list of prompts needed to continue
  852. * may be NULL if callbacks provided
  853. * clientout -- the initial client response to send to the server
  854. * will be valid until next call to client_start/client_step
  855. * NULL if mech doesn't include initial client challenge
  856. * mech -- set to mechansm name of selected mechanism (may be NULL)
  857. *
  858. * Returns:
  859. * SASL_OK -- success
  860. * SASL_NOMEM -- not enough memory
  861. * SASL_NOMECH -- no mechanism meets requested properties
  862. * SASL_INTERACT -- user interaction needed to fill in prompt_need list
  863. */
  864. LIBSASL_API int sasl_client_start(sasl_conn_t *conn,
  865. const char *mechlist,
  866. sasl_interact_t **prompt_need,
  867. const char **clientout,
  868. unsigned *clientoutlen,
  869. const char **mech);
  870. /* do a single authentication step.
  871. * serverin -- the server message received by the client, MUST have a NUL
  872. * sentinel, not counted by serverinlen
  873. * output:
  874. * prompt_need -- on SASL_INTERACT, list of prompts needed to continue
  875. * clientout -- the client response to send to the server
  876. * will be valid until next call to client_start/client_step
  877. *
  878. * returns:
  879. * SASL_OK -- success
  880. * SASL_INTERACT -- user interaction needed to fill in prompt_need list
  881. * SASL_BADPROT -- server protocol incorrect/cancelled
  882. * SASL_BADSERV -- server failed mutual auth
  883. */
  884. LIBSASL_API int sasl_client_step(sasl_conn_t *conn,
  885. const char *serverin,
  886. unsigned serverinlen,
  887. sasl_interact_t **prompt_need,
  888. const char **clientout,
  889. unsigned *clientoutlen);
  890. /**************
  891. * Server API *
  892. **************/
  893. /* initialize server drivers, done once per process
  894. * callbacks -- callbacks for all server connections; must include
  895. * getopt callback
  896. * appname -- name of calling application (for lower level logging)
  897. * results:
  898. * state -- server state
  899. * returns:
  900. * SASL_OK -- success
  901. * SASL_BADPARAM -- error in config file
  902. * SASL_NOMEM -- memory failure
  903. * SASL_BADVERS -- Mechanism version mismatch
  904. */
  905. LIBSASL_API int sasl_server_init(const sasl_callback_t *callbacks,
  906. const char *appname);
  907. /* IP/port syntax:
  908. * a.b.c.d;p where a-d are 0-255 and p is 0-65535 port number.
  909. * e:f:g:h:i:j:k:l;p where e-l are 0000-ffff lower-case hexidecimal
  910. * e:f:g:h:i:j:a.b.c.d;p alternate syntax for previous
  911. *
  912. * Note that one or more "0" fields in f-k can be replaced with "::"
  913. * Thus: e:f:0000:0000:0000:j:k:l;p
  914. * can be abbreviated: e:f::j:k:l;p
  915. *
  916. * A buffer of size 52 is adequate for the longest format with NUL terminator.
  917. */
  918. /* create context for a single SASL connection
  919. * service -- registered name of the service using SASL (e.g. "imap")
  920. * serverFQDN -- Fully qualified domain name of server. NULL means use
  921. * gethostname() or equivalent.
  922. * Useful for multi-homed servers.
  923. * user_realm -- permits multiple user realms on server, NULL = default
  924. * iplocalport -- server IPv4/IPv6 domain literal string with port
  925. * (if NULL, then mechanisms requiring IPaddr are disabled)
  926. * ipremoteport -- client IPv4/IPv6 domain literal string with port
  927. * (if NULL, then mechanisms requiring IPaddr are disabled)
  928. * callbacks -- callbacks (e.g., authorization, lang, new getopt context)
  929. * flags -- usage flags (see above)
  930. * returns:
  931. * pconn -- new connection context
  932. *
  933. * returns:
  934. * SASL_OK -- success
  935. * SASL_NOMEM -- not enough memory
  936. */
  937. LIBSASL_API int sasl_server_new(const char *service,
  938. const char *serverFQDN,
  939. const char *user_realm,
  940. const char *iplocalport,
  941. const char *ipremoteport,
  942. const sasl_callback_t *callbacks,
  943. unsigned flags,
  944. sasl_conn_t **pconn);
  945. /* Return an array of NUL-terminated strings, terminated by a NULL pointer,
  946. * which lists all possible mechanisms that the library can supply
  947. *
  948. * Returns NULL on failure. */
  949. LIBSASL_API const char ** sasl_global_listmech(void);
  950. /* This returns a list of mechanisms in a NUL-terminated string
  951. * conn -- the connection to list mechanisms for (either client
  952. * or server)
  953. * user -- restricts mechanisms to those available to that user
  954. * (may be NULL, not used for client case)
  955. * prefix -- appended to beginning of result
  956. * sep -- appended between mechanisms
  957. * suffix -- appended to end of result
  958. * results:
  959. * result -- NUL terminated result which persists until next
  960. * call to sasl_listmech for this sasl_conn_t
  961. * plen -- gets length of result (excluding NUL), may be NULL
  962. * pcount -- gets number of mechanisms, may be NULL
  963. *
  964. * returns:
  965. * SASL_OK -- success
  966. * SASL_NOMEM -- not enough memory
  967. * SASL_NOMECH -- no enabled mechanisms
  968. */
  969. LIBSASL_API int sasl_listmech(sasl_conn_t *conn,
  970. const char *user,
  971. const char *prefix,
  972. const char *sep,
  973. const char *suffix,
  974. const char **result,
  975. unsigned *plen,
  976. int *pcount);
  977. /* start a mechanism exchange within a connection context
  978. * mech -- the mechanism name client requested
  979. * clientin -- client initial response (NUL terminated), NULL if empty
  980. * clientinlen -- length of initial response
  981. * serverout -- initial server challenge, NULL if done
  982. * (library handles freeing this string)
  983. * serveroutlen -- length of initial server challenge
  984. * output:
  985. * pconn -- the connection negotiation state on success
  986. *
  987. * Same returns as sasl_server_step() or
  988. * SASL_NOMECH if mechanism not available.
  989. */
  990. LIBSASL_API int sasl_server_start(sasl_conn_t *conn,
  991. const char *mech,
  992. const char *clientin,
  993. unsigned clientinlen,
  994. const char **serverout,
  995. unsigned *serveroutlen);
  996. /* perform one step of the SASL exchange
  997. * inputlen & input -- client data
  998. * NULL on first step if no optional client step
  999. * outputlen & output -- set to the server data to transmit
  1000. * to the client in the next step
  1001. * (library handles freeing this)
  1002. *
  1003. * returns:
  1004. * SASL_OK -- exchange is complete.
  1005. * SASL_CONTINUE -- indicates another step is necessary.
  1006. * SASL_TRANS -- entry for user exists, but not for mechanism
  1007. * and transition is possible
  1008. * SASL_BADPARAM -- service name needed
  1009. * SASL_BADPROT -- invalid input from client
  1010. * ...
  1011. */
  1012. LIBSASL_API int sasl_server_step(sasl_conn_t *conn,
  1013. const char *clientin,
  1014. unsigned clientinlen,
  1015. const char **serverout,
  1016. unsigned *serveroutlen);
  1017. /* check if an apop exchange is valid
  1018. * (note this is an optional part of the SASL API)
  1019. * if challenge is NULL, just check if APOP is enabled
  1020. * inputs:
  1021. * challenge -- challenge which was sent to client
  1022. * challen -- length of challenge, 0 = strlen(challenge)
  1023. * response -- client response, "<user> <digest>" (RFC 1939)
  1024. * resplen -- length of response, 0 = strlen(response)
  1025. * returns
  1026. * SASL_OK -- success
  1027. * SASL_BADAUTH -- authentication failed
  1028. * SASL_BADPARAM -- missing challenge
  1029. * SASL_BADPROT -- protocol error (e.g., response in wrong format)
  1030. * SASL_NOVERIFY -- user found, but no verifier
  1031. * SASL_NOMECH -- mechanism not supported
  1032. * SASL_NOUSER -- user not found
  1033. */
  1034. LIBSASL_API int sasl_checkapop(sasl_conn_t *conn,
  1035. const char *challenge, unsigned challen,
  1036. const char *response, unsigned resplen);
  1037. /* check if a plaintext password is valid
  1038. * if user is NULL, check if plaintext passwords are enabled
  1039. * inputs:
  1040. * user -- user to query in current user_domain
  1041. * userlen -- length of username, 0 = strlen(user)
  1042. * pass -- plaintext password to check
  1043. * passlen -- length of password, 0 = strlen(pass)
  1044. * returns
  1045. * SASL_OK -- success
  1046. * SASL_NOMECH -- mechanism not supported
  1047. * SASL_NOVERIFY -- user found, but no verifier
  1048. * SASL_NOUSER -- user not found
  1049. */
  1050. LIBSASL_API int sasl_checkpass(sasl_conn_t *conn,
  1051. const char *user, unsigned userlen,
  1052. const char *pass, unsigned passlen);
  1053. /* check if a user exists on server
  1054. * conn -- connection context
  1055. * service -- registered name of the service using SASL (e.g. "imap")
  1056. * user_realm -- permits multiple user realms on server, NULL = default
  1057. * user -- NUL terminated user name
  1058. *
  1059. * returns:
  1060. * SASL_OK -- success
  1061. * SASL_DISABLED -- account disabled
  1062. * SASL_NOUSER -- user not found
  1063. * SASL_NOVERIFY -- user found, but no usable mechanism
  1064. * SASL_NOMECH -- no mechanisms enabled
  1065. * SASL_UNAVAIL -- remote authentication server unavailable, try again later
  1066. */
  1067. LIBSASL_API int sasl_user_exists(sasl_conn_t *conn,
  1068. const char *service,
  1069. const char *user_realm,
  1070. const char *user);
  1071. /* set the password for a user
  1072. * conn -- SASL connection
  1073. * user -- user name
  1074. * pass -- plaintext password, may be NULL to remove user
  1075. * passlen -- length of password, 0 = strlen(pass)
  1076. * oldpass -- NULL will sometimes work
  1077. * oldpasslen -- length of password, 0 = strlen(oldpass)
  1078. * flags -- see flags below
  1079. *
  1080. * returns:
  1081. * SASL_NOCHANGE -- proper entry already exists
  1082. * SASL_NOMECH -- no authdb supports password setting as configured
  1083. * SASL_NOVERIFY -- user exists, but no settable password present
  1084. * SASL_DISABLED -- account disabled
  1085. * SASL_PWLOCK -- password locked
  1086. * SASL_WEAKPASS -- password too weak for security policy
  1087. * SASL_NOUSERPASS -- user-supplied passwords not permitted
  1088. * SASL_FAIL -- OS error
  1089. * SASL_BADPARAM -- password too long
  1090. * SASL_OK -- successful
  1091. */
  1092. LIBSASL_API int sasl_setpass(sasl_conn_t *conn,
  1093. const char *user,
  1094. const char *pass, unsigned passlen,
  1095. const char *oldpass, unsigned oldpasslen,
  1096. unsigned flags);
  1097. #define SASL_SET_CREATE 0x01 /* create a new entry for user */
  1098. #define SASL_SET_DISABLE 0x02 /* disable user account */
  1099. #define SASL_SET_NOPLAIN 0x04 /* do not store secret in plain text */
  1100. #define SASL_SET_CURMECH_ONLY 0x08 /* set the mechanism specific password only.
  1101. fail if no current mechanism */
  1102. /*********************************************************
  1103. * Auxiliary Property Support -- added by cjn 1999-09-29 *
  1104. *********************************************************/
  1105. #define SASL_AUX_END NULL /* last auxiliary property */
  1106. #define SASL_AUX_ALL "*" /* A special flag to signal user deletion */
  1107. /* traditional Posix items (should be implemented on Posix systems) */
  1108. #define SASL_AUX_PASSWORD_PROP "userPassword" /* User Password */
  1109. #define SASL_AUX_PASSWORD "*" SASL_AUX_PASSWORD_PROP /* User Password (of authid) */
  1110. #define SASL_AUX_UIDNUM "uidNumber" /* UID number for the user */
  1111. #define SASL_AUX_GIDNUM "gidNumber" /* GID for the user */
  1112. #define SASL_AUX_FULLNAME "gecos" /* full name of the user, unix-style */
  1113. #define SASL_AUX_HOMEDIR "homeDirectory" /* home directory for user */
  1114. #define SASL_AUX_SHELL "loginShell" /* login shell for the user */
  1115. /* optional additional items (not necessarily implemented) */
  1116. /* single preferred mail address for user canonically-quoted
  1117. * RFC821/822 syntax */
  1118. #define SASL_AUX_MAILADDR "mail"
  1119. /* path to unix-style mailbox for user */
  1120. #define SASL_AUX_UNIXMBX "mailMessageStore"
  1121. /* SMTP mail channel name to use if user authenticates successfully */
  1122. #define SASL_AUX_MAILCHAN "mailSMTPSubmitChannel"
  1123. /* Request a set of auxiliary properties
  1124. * conn connection context
  1125. * propnames list of auxiliary property names to request ending with
  1126. * NULL.
  1127. *
  1128. * Subsequent calls will add items to the request list. Call with NULL
  1129. * to clear the request list.
  1130. *
  1131. * errors
  1132. * SASL_OK -- success
  1133. * SASL_BADPARAM -- bad count/conn parameter
  1134. * SASL_NOMEM -- out of memory
  1135. */
  1136. LIBSASL_API int sasl_auxprop_request(sasl_conn_t *conn,
  1137. const char **propnames);
  1138. /* Returns current auxiliary property context.
  1139. * Use functions in prop.h to access content
  1140. *
  1141. * if authentication hasn't completed, property values may be empty/NULL
  1142. *
  1143. * properties not recognized by active plug-ins will be left empty/NULL
  1144. *
  1145. * returns NULL if conn is invalid.
  1146. */
  1147. LIBSASL_API struct propctx *sasl_auxprop_getctx(sasl_conn_t *conn);
  1148. /* Store the set of auxiliary properties for the given user.
  1149. * Use functions in prop.h to set the content.
  1150. *
  1151. * conn connection context
  1152. * ctx property context from prop_new()/prop_request()/prop_set()
  1153. * user NUL terminated user
  1154. *
  1155. * Call with NULL 'ctx' to see if the backend allows storing properties.
  1156. *
  1157. * errors
  1158. * SASL_OK -- success
  1159. * SASL_NOMECH -- can not store some/all properties
  1160. * SASL_BADPARAM -- bad conn/ctx/user parameter
  1161. * SASL_NOMEM -- out of memory
  1162. * SASL_FAIL -- failed to store
  1163. */
  1164. LIBSASL_API int sasl_auxprop_store(sasl_conn_t *conn,
  1165. struct propctx *ctx, const char *user);
  1166. /**********************
  1167. * security layer API *
  1168. **********************/
  1169. /* encode a block of data for transmission using security layer,
  1170. * returning the input buffer if there is no security layer.
  1171. * output is only valid until next call to sasl_encode or sasl_encodev
  1172. * returns:
  1173. * SASL_OK -- success (returns input if no layer negotiated)
  1174. * SASL_NOTDONE -- security layer negotiation not finished
  1175. * SASL_BADPARAM -- inputlen is greater than the SASL_MAXOUTBUF
  1176. */
  1177. LIBSASL_API int sasl_encode(sasl_conn_t *conn,
  1178. const char *input, unsigned inputlen,
  1179. const char **output, unsigned *outputlen);
  1180. /* encode a block of data for transmission using security layer
  1181. * output is only valid until next call to sasl_encode or sasl_encodev
  1182. * returns:
  1183. * SASL_OK -- success (returns input if no layer negotiated)
  1184. * SASL_NOTDONE -- security layer negotiation not finished
  1185. * SASL_BADPARAM -- input length is greater than the SASL_MAXOUTBUF
  1186. * or no security layer
  1187. */
  1188. LIBSASL_API int sasl_encodev(sasl_conn_t *conn,
  1189. const struct iovec *invec, unsigned numiov,
  1190. const char **output, unsigned *outputlen);
  1191. /* decode a block of data received using security layer
  1192. * returning the input buffer if there is no security layer.
  1193. * output is only valid until next call to sasl_decode
  1194. *
  1195. * if outputlen is 0 on return, than the value of output is undefined.
  1196. *
  1197. * returns:
  1198. * SASL_OK -- success (returns input if no layer negotiated)
  1199. * SASL_NOTDONE -- security layer negotiation not finished
  1200. * SASL_BADMAC -- bad message integrity check
  1201. */
  1202. LIBSASL_API int sasl_decode(sasl_conn_t *conn,
  1203. const char *input, unsigned inputlen,
  1204. const char **output, unsigned *outputlen);
  1205. #ifdef __cplusplus
  1206. }
  1207. #endif
  1208. #endif /* SASL_H */