saslplug.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. /* saslplug.h -- API for SASL plug-ins
  2. */
  3. #ifndef SASLPLUG_H
  4. #define SASLPLUG_H 1
  5. #ifndef MD5GLOBAL_H
  6. #include "md5global.h"
  7. #endif
  8. #ifndef MD5_H
  9. #include "md5.h"
  10. #endif
  11. #ifndef HMAC_MD5_H
  12. #include "hmac-md5.h"
  13. #endif
  14. #ifndef PROP_H
  15. #include "prop.h"
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /* callback to lookup a sasl_callback_t for a connection
  21. * input:
  22. * conn -- the connection to lookup a callback for
  23. * callbacknum -- the number of the callback
  24. * output:
  25. * pproc -- pointer to the callback function (set to NULL on failure)
  26. * pcontext -- pointer to the callback context (set to NULL on failure)
  27. * returns:
  28. * SASL_OK -- no error
  29. * SASL_FAIL -- unable to find a callback of the requested type
  30. * SASL_INTERACT -- caller must use interaction to get data
  31. */
  32. typedef int (*sasl_callback_ft)(void);
  33. typedef int sasl_getcallback_t(sasl_conn_t *conn,
  34. unsigned long callbackid,
  35. sasl_callback_ft * pproc,
  36. void **pcontext);
  37. /* The sasl_utils structure will remain backwards compatible unless
  38. * the SASL_*_PLUG_VERSION is changed incompatibly
  39. * higher SASL_UTILS_VERSION numbers indicate more functions are available
  40. */
  41. #define SASL_UTILS_VERSION 4
  42. /* utility function set for plug-ins
  43. */
  44. typedef struct sasl_utils {
  45. int version;
  46. /* contexts */
  47. sasl_conn_t *conn;
  48. sasl_rand_t *rpool;
  49. void *getopt_context;
  50. /* option function */
  51. sasl_getopt_t *getopt;
  52. /* allocation functions: */
  53. sasl_malloc_t *malloc;
  54. sasl_calloc_t *calloc;
  55. sasl_realloc_t *realloc;
  56. sasl_free_t *free;
  57. /* mutex functions: */
  58. sasl_mutex_alloc_t *mutex_alloc;
  59. sasl_mutex_lock_t *mutex_lock;
  60. sasl_mutex_unlock_t *mutex_unlock;
  61. sasl_mutex_free_t *mutex_free;
  62. /* MD5 hash and HMAC functions */
  63. void (*MD5Init)(MD5_CTX *);
  64. void (*MD5Update)(MD5_CTX *, const unsigned char *text, unsigned int len);
  65. void (*MD5Final)(unsigned char [16], MD5_CTX *);
  66. void (*hmac_md5)(const unsigned char *text, int text_len,
  67. const unsigned char *key, int key_len,
  68. unsigned char [16]);
  69. void (*hmac_md5_init)(HMAC_MD5_CTX *, const unsigned char *key, int len);
  70. /* hmac_md5_update() is just a call to MD5Update on inner context */
  71. void (*hmac_md5_final)(unsigned char [16], HMAC_MD5_CTX *);
  72. void (*hmac_md5_precalc)(HMAC_MD5_STATE *,
  73. const unsigned char *key, int len);
  74. void (*hmac_md5_import)(HMAC_MD5_CTX *, HMAC_MD5_STATE *);
  75. /* mechanism utility functions (same as above): */
  76. int (*mkchal)(sasl_conn_t *conn, char *buf, unsigned maxlen,
  77. unsigned hostflag);
  78. int (*utf8verify)(const char *str, unsigned len);
  79. void (*rand)(sasl_rand_t *rpool, char *buf, unsigned len);
  80. void (*churn)(sasl_rand_t *rpool, const char *data, unsigned len);
  81. /* This allows recursive calls to the sasl_checkpass() routine from
  82. * within a SASL plug-in. This MUST NOT be used in the PLAIN mechanism
  83. * as sasl_checkpass MAY be a front-end for the PLAIN mechanism.
  84. * This is intended for use by the non-standard LOGIN mechanism and
  85. * potentially by a future mechanism which uses public-key technology to
  86. * set up a lightweight encryption layer just for sending a password.
  87. */
  88. int (*checkpass)(sasl_conn_t *conn,
  89. const char *user, unsigned userlen,
  90. const char *pass, unsigned passlen);
  91. /* Access to base64 encode/decode routines */
  92. int (*decode64)(const char *in, unsigned inlen,
  93. char *out, unsigned outmax, unsigned *outlen);
  94. int (*encode64)(const char *in, unsigned inlen,
  95. char *out, unsigned outmax, unsigned *outlen);
  96. /* erase a buffer */
  97. void (*erasebuffer)(char *buf, unsigned len);
  98. /* callback to sasl_getprop() and sasl_setprop() */
  99. int (*getprop)(sasl_conn_t *conn, int propnum, const void **pvalue);
  100. int (*setprop)(sasl_conn_t *conn, int propnum, const void *value);
  101. /* callback function */
  102. sasl_getcallback_t *getcallback;
  103. /* format a message and then pass it to the SASL_CB_LOG callback
  104. *
  105. * use syslog()-style formatting (printf with %m as a human readable text
  106. * (strerror()) for the error specified as the parameter).
  107. * The implementation may use a fixed size buffer not smaller
  108. * than 512 octets if it securely truncates the message.
  109. *
  110. * level is a SASL_LOG_* level (see sasl.h)
  111. */
  112. void (*log)(sasl_conn_t *conn, int level, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
  113. /* callback to sasl_seterror() */
  114. void (*seterror)(sasl_conn_t *conn, unsigned flags, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
  115. /* spare function pointer */
  116. int *(*spare_fptr)(void);
  117. /* auxiliary property utilities */
  118. struct propctx *(*prop_new)(unsigned estimate);
  119. int (*prop_dup)(struct propctx *src_ctx, struct propctx **dst_ctx);
  120. int (*prop_request)(struct propctx *ctx, const char **names);
  121. const struct propval *(*prop_get)(struct propctx *ctx);
  122. int (*prop_getnames)(struct propctx *ctx, const char **names,
  123. struct propval *vals);
  124. void (*prop_clear)(struct propctx *ctx, int requests);
  125. void (*prop_dispose)(struct propctx **ctx);
  126. int (*prop_format)(struct propctx *ctx, const char *sep, int seplen,
  127. char *outbuf, unsigned outmax, unsigned *outlen);
  128. int (*prop_set)(struct propctx *ctx, const char *name,
  129. const char *value, int vallen);
  130. int (*prop_setvals)(struct propctx *ctx, const char *name,
  131. const char **values);
  132. void (*prop_erase)(struct propctx *ctx, const char *name);
  133. int (*auxprop_store)(sasl_conn_t *conn,
  134. struct propctx *ctx, const char *user);
  135. /* for additions which don't require a version upgrade; set to 0 */
  136. int (*spare_fptr1)(void);
  137. int (*spare_fptr2)(void);
  138. } sasl_utils_t;
  139. /*
  140. * output parameters from SASL API
  141. *
  142. * created / destroyed by the glue code, though probably filled in
  143. * by a combination of the plugin, the glue code, and the canon_user callback.
  144. *
  145. */
  146. typedef struct sasl_out_params {
  147. unsigned doneflag; /* exchange complete */
  148. const char *user; /* canonicalized user name */
  149. const char *authid; /* canonicalized authentication id */
  150. unsigned ulen; /* length of canonicalized user name */
  151. unsigned alen; /* length of canonicalized authid */
  152. /* security layer information */
  153. unsigned maxoutbuf; /* Maximum buffer size, which will
  154. produce buffer no bigger than the
  155. negotiated SASL maximum buffer size */
  156. sasl_ssf_t mech_ssf; /* Should be set non-zero if negotiation of a
  157. * security layer was *attempted*, even if
  158. * the negotiation failed */
  159. void *encode_context;
  160. int (*encode)(void *context, const struct iovec *invec, unsigned numiov,
  161. const char **output, unsigned *outputlen);
  162. void *decode_context;
  163. int (*decode)(void *context, const char *input, unsigned inputlen,
  164. const char **output, unsigned *outputlen);
  165. /* Pointer to delegated (client's) credentials, if supported by
  166. the SASL mechanism */
  167. void *client_creds;
  168. /* for additions which don't require a version upgrade; set to 0 */
  169. const void *gss_peer_name;
  170. const void *gss_local_name;
  171. const char *cbindingname; /* channel binding name from packet */
  172. int (*spare_fptr1)(void);
  173. int (*spare_fptr2)(void);
  174. unsigned int cbindingdisp; /* channel binding disposition from client */
  175. int spare_int2;
  176. int spare_int3;
  177. int spare_int4;
  178. /* set to 0 initially, this allows a plugin with extended parameters
  179. * to work with an older framework by updating version as parameters
  180. * are added.
  181. */
  182. int param_version;
  183. } sasl_out_params_t;
  184. /* Used by both client and server side plugins */
  185. typedef enum {
  186. SASL_INFO_LIST_START = 0,
  187. SASL_INFO_LIST_MECH,
  188. SASL_INFO_LIST_END
  189. } sasl_info_callback_stage_t;
  190. /******************************
  191. * Channel binding macros **
  192. ******************************/
  193. typedef enum {
  194. SASL_CB_DISP_NONE = 0, /* client did not support CB */
  195. SASL_CB_DISP_WANT, /* client supports CB, thinks server does not */
  196. SASL_CB_DISP_USED /* client supports and used CB */
  197. } sasl_cbinding_disp_t;
  198. /* TRUE if channel binding is non-NULL */
  199. #define SASL_CB_PRESENT(params) ((params)->cbinding != NULL)
  200. /* TRUE if channel binding is marked critical */
  201. #define SASL_CB_CRITICAL(params) (SASL_CB_PRESENT(params) && \
  202. (params)->cbinding->critical)
  203. /******************************
  204. * Client Mechanism Functions *
  205. ******************************/
  206. /*
  207. * input parameters to client SASL plugin
  208. *
  209. * created / destroyed by the glue code
  210. *
  211. */
  212. typedef struct sasl_client_params {
  213. const char *service; /* service name */
  214. const char *serverFQDN; /* server fully qualified domain name */
  215. const char *clientFQDN; /* client's fully qualified domain name */
  216. const sasl_utils_t *utils; /* SASL API utility routines --
  217. * for a particular sasl_conn_t,
  218. * MUST remain valid until mech_free is
  219. * called */
  220. const sasl_callback_t *prompt_supp; /* client callback list */
  221. const char *iplocalport; /* server IP domain literal & port */
  222. const char *ipremoteport; /* client IP domain literal & port */
  223. unsigned servicelen; /* length of service */
  224. unsigned slen; /* length of serverFQDN */
  225. unsigned clen; /* length of clientFQDN */
  226. unsigned iploclen; /* length of iplocalport */
  227. unsigned ipremlen; /* length of ipremoteport */
  228. /* application's security requirements & info */
  229. sasl_security_properties_t props;
  230. sasl_ssf_t external_ssf; /* external SSF active */
  231. /* for additions which don't require a version upgrade; set to 0 */
  232. const void *gss_creds; /* GSS credential handle */
  233. const sasl_channel_binding_t *cbinding; /* client channel binding */
  234. const sasl_http_request_t *http_request;/* HTTP Digest request method */
  235. void *spare_ptr4;
  236. /* Canonicalize a user name from on-wire to internal format
  237. * added rjs3 2001-05-23
  238. * Must be called once user name aquired if canon_user is non-NULL.
  239. * conn connection context
  240. * in user name from wire protocol (need not be NUL terminated)
  241. * len length of user name from wire protocol (0 = strlen(user))
  242. * flags for SASL_CU_* flags
  243. * oparams the user, authid, ulen, alen, fields are
  244. * set appropriately after canonicalization/copying and
  245. * authorization of arguments
  246. *
  247. * responsible for setting user, ulen, authid, and alen in the oparams
  248. * structure
  249. *
  250. * default behavior is to strip leading and trailing whitespace, as
  251. * well as allocating space for and copying the parameters.
  252. *
  253. * results:
  254. * SASL_OK -- success
  255. * SASL_NOMEM -- out of memory
  256. * SASL_BADPARAM -- invalid conn
  257. * SASL_BADPROT -- invalid user/authid
  258. */
  259. int (*canon_user)(sasl_conn_t *conn,
  260. const char *in, unsigned len,
  261. unsigned flags,
  262. sasl_out_params_t *oparams);
  263. int (*spare_fptr1)(void);
  264. unsigned int cbindingdisp;
  265. int spare_int2;
  266. int spare_int3;
  267. /* flags field as passed to sasl_client_new */
  268. unsigned flags;
  269. /* set to 0 initially, this allows a plugin with extended parameters
  270. * to work with an older framework by updating version as parameters
  271. * are added.
  272. */
  273. int param_version;
  274. } sasl_client_params_t;
  275. /* features shared between client and server */
  276. /* These allow the glue code to handle client-first and server-last issues */
  277. /* This indicates that the mechanism prefers to do client-send-first
  278. * if the protocol allows it. */
  279. #define SASL_FEAT_WANT_CLIENT_FIRST 0x0002
  280. /* This feature is deprecated. Instead, plugins should set *serverout to
  281. * non-NULL and return SASL_OK intelligently to allow flexible use of
  282. * server-last semantics
  283. #define SASL_FEAT_WANT_SERVER_LAST 0x0004
  284. */
  285. /* This feature is deprecated. Instead, plugins should correctly set
  286. * SASL_FEAT_SERVER_FIRST as needed
  287. #define SASL_FEAT_INTERNAL_CLIENT_FIRST 0x0008
  288. */
  289. /* This indicates that the plugin is server-first only.
  290. * Not defining either of SASL_FEAT_SERVER_FIRST or
  291. * SASL_FEAT_WANT_CLIENT_FIRST indicates that the mechanism
  292. * will handle the client-first situation internally.
  293. */
  294. #define SASL_FEAT_SERVER_FIRST 0x0010
  295. /* This plugin allows proxying */
  296. #define SASL_FEAT_ALLOWS_PROXY 0x0020
  297. /* server plugin don't use cleartext userPassword attribute */
  298. #define SASL_FEAT_DONTUSE_USERPASSWD 0x0080
  299. /* Underlying mechanism uses GSS framing */
  300. #define SASL_FEAT_GSS_FRAMING 0x0100
  301. /* Underlying mechanism supports channel binding */
  302. #define SASL_FEAT_CHANNEL_BINDING 0x0800
  303. /* This plugin can be used for HTTP authentication */
  304. #define SASL_FEAT_SUPPORTS_HTTP 0x1000
  305. /* client plug-in features */
  306. #define SASL_FEAT_NEEDSERVERFQDN 0x0001
  307. /* a C object for a client mechanism
  308. */
  309. typedef struct sasl_client_plug {
  310. /* mechanism name */
  311. const char *mech_name;
  312. /* best mech additional security layer strength factor */
  313. sasl_ssf_t max_ssf;
  314. /* best security flags, as defined in sasl_security_properties_t */
  315. unsigned security_flags;
  316. /* features of plugin */
  317. unsigned features;
  318. /* required prompt ids, NULL = user/pass only */
  319. const unsigned long *required_prompts;
  320. /* global state for mechanism */
  321. void *glob_context;
  322. /* create context for mechanism, using params supplied
  323. * glob_context -- from above
  324. * params -- params from sasl_client_new
  325. * conn_context -- context for one connection
  326. * returns:
  327. * SASL_OK -- success
  328. * SASL_NOMEM -- not enough memory
  329. * SASL_WRONGMECH -- mech doesn't support security params
  330. */
  331. int (*mech_new)(void *glob_context,
  332. sasl_client_params_t *cparams,
  333. void **conn_context);
  334. /* perform one step of exchange. NULL is passed for serverin on
  335. * first step.
  336. * returns:
  337. * SASL_OK -- success
  338. * SASL_INTERACT -- user interaction needed to fill in prompts
  339. * SASL_BADPROT -- server protocol incorrect/cancelled
  340. * SASL_BADSERV -- server failed mutual auth
  341. */
  342. int (*mech_step)(void *conn_context,
  343. sasl_client_params_t *cparams,
  344. const char *serverin,
  345. unsigned serverinlen,
  346. sasl_interact_t **prompt_need,
  347. const char **clientout,
  348. unsigned *clientoutlen,
  349. sasl_out_params_t *oparams);
  350. /* dispose of connection context from mech_new
  351. */
  352. void (*mech_dispose)(void *conn_context, const sasl_utils_t *utils);
  353. /* free all global space used by mechanism
  354. * mech_dispose must be called on all mechanisms first
  355. */
  356. void (*mech_free)(void *glob_context, const sasl_utils_t *utils);
  357. /* perform precalculations during a network round-trip
  358. * or idle period. conn_context may be NULL
  359. * returns 1 if action taken, 0 if no action taken
  360. */
  361. int (*idle)(void *glob_context,
  362. void *conn_context,
  363. sasl_client_params_t *cparams);
  364. /* for additions which don't require a version upgrade; set to 0 */
  365. int (*spare_fptr1)(void);
  366. int (*spare_fptr2)(void);
  367. } sasl_client_plug_t;
  368. #define SASL_CLIENT_PLUG_VERSION 4
  369. /* plug-in entry point:
  370. * utils -- utility callback functions
  371. * max_version -- highest client plug version supported
  372. * returns:
  373. * out_version -- client plug version of result
  374. * pluglist -- list of mechanism plug-ins
  375. * plugcount -- number of mechanism plug-ins
  376. * results:
  377. * SASL_OK -- success
  378. * SASL_NOMEM -- failure
  379. * SASL_BADVERS -- max_version too small
  380. * SASL_BADPARAM -- bad config string
  381. * ...
  382. */
  383. typedef int sasl_client_plug_init_t(const sasl_utils_t *utils,
  384. int max_version,
  385. int *out_version,
  386. sasl_client_plug_t **pluglist,
  387. int *plugcount);
  388. /* add a client plug-in
  389. */
  390. LIBSASL_API int sasl_client_add_plugin(const char *plugname,
  391. sasl_client_plug_init_t *cplugfunc);
  392. typedef struct client_sasl_mechanism
  393. {
  394. int version;
  395. char *plugname;
  396. const sasl_client_plug_t *plug;
  397. } client_sasl_mechanism_t;
  398. typedef void sasl_client_info_callback_t (client_sasl_mechanism_t *m,
  399. sasl_info_callback_stage_t stage,
  400. void *rock);
  401. /* Dump information about available client plugins */
  402. LIBSASL_API int sasl_client_plugin_info (const char *mech_list,
  403. sasl_client_info_callback_t *info_cb,
  404. void *info_cb_rock);
  405. /********************
  406. * Server Functions *
  407. ********************/
  408. /* log message formatting routine */
  409. typedef void sasl_logmsg_p(sasl_conn_t *conn, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
  410. /*
  411. * input parameters to server SASL plugin
  412. *
  413. * created / destroyed by the glue code
  414. *
  415. */
  416. typedef struct sasl_server_params {
  417. const char *service; /* NULL = default service for user_exists
  418. and setpass */
  419. const char *appname; /* name of calling application */
  420. const char *serverFQDN; /* server default fully qualified domain name
  421. * (e.g., gethostname) */
  422. const char *user_realm; /* realm for user (NULL = client supplied) */
  423. const char *iplocalport; /* server IP domain literal & port */
  424. const char *ipremoteport; /* client IP domain literal & port */
  425. unsigned servicelen; /* length of service */
  426. unsigned applen; /* length of appname */
  427. unsigned slen; /* length of serverFQDN */
  428. unsigned urlen; /* length of user_realm */
  429. unsigned iploclen; /* length of iplocalport */
  430. unsigned ipremlen; /* length of ipremoteport */
  431. /* This indicates the level of logging desired. See SASL_LOG_*
  432. * in sasl.h
  433. *
  434. * Plug-ins can ignore this and just pass their desired level to
  435. * the log callback. This is primarily used to eliminate logging which
  436. * might be a performance problem (e.g., full protocol trace) and
  437. * to select between SASL_LOG_TRACE and SASL_LOG_PASS alternatives
  438. */
  439. int log_level;
  440. const sasl_utils_t *utils; /* SASL API utility routines --
  441. * for a particular sasl_conn_t,
  442. * MUST remain valid until mech_free is
  443. * called */
  444. const sasl_callback_t *callbacks; /* Callbacks from application */
  445. /* application's security requirements */
  446. sasl_security_properties_t props;
  447. sasl_ssf_t external_ssf; /* external SSF active */
  448. /* Pointer to the function which takes the plaintext passphrase and
  449. * transitions a user to non-plaintext mechanisms via setpass calls.
  450. * (NULL = auto transition not enabled/supported)
  451. *
  452. * If passlen is 0, it defaults to strlen(pass).
  453. * returns 0 if no entry added, 1 if entry added
  454. */
  455. int (*transition)(sasl_conn_t *conn, const char *pass, unsigned passlen);
  456. /* Canonicalize a user name from on-wire to internal format
  457. * added cjn 1999-09-21
  458. * Must be called once user name acquired if canon_user is non-NULL.
  459. * conn connection context
  460. * user user name from wire protocol (need not be NUL terminated)
  461. * ulen length of user name from wire protocol (0 = strlen(user))
  462. * flags for SASL_CU_* flags
  463. * oparams the user, authid, ulen, alen, fields are
  464. * set appropriately after canonicalization/copying and
  465. * authorization of arguments
  466. *
  467. * responsible for setting user, ulen, authid, and alen in the oparams
  468. * structure
  469. *
  470. * default behavior is to strip leading and trailing whitespace, as
  471. * well as allocating space for and copying the parameters.
  472. *
  473. * results:
  474. * SASL_OK -- success
  475. * SASL_NOMEM -- out of memory
  476. * SASL_BADPARAM -- invalid conn
  477. * SASL_BADPROT -- invalid user/authid
  478. */
  479. int (*canon_user)(sasl_conn_t *conn,
  480. const char *user, unsigned ulen,
  481. unsigned flags,
  482. sasl_out_params_t *oparams);
  483. /* auxiliary property context (see definitions in prop.h)
  484. * added cjn 2000-01-30
  485. *
  486. * NOTE: these properties are the ones associated with the
  487. * canonicalized "user" (user to login as / authorization id), not
  488. * the "authid" (user whose credentials are used / authentication id)
  489. * Prefix the property name with a "*" if a property associated with
  490. * the "authid" is interesting.
  491. */
  492. struct propctx *propctx;
  493. /* for additions which don't require a version upgrade; set to 0 */
  494. const void *gss_creds; /* GSS credential handle */
  495. const sasl_channel_binding_t *cbinding; /* server channel binding */
  496. const sasl_http_request_t *http_request;/* HTTP Digest request method */
  497. void *spare_ptr4;
  498. int (*spare_fptr1)(void);
  499. int (*spare_fptr2)(void);
  500. int spare_int1;
  501. int spare_int2;
  502. int spare_int3;
  503. /* flags field as passed to sasl_server_new */
  504. unsigned flags;
  505. /* set to 0 initially, this allows a plugin with extended parameters
  506. * to work with an older framework by updating version as parameters
  507. * are added.
  508. */
  509. int param_version;
  510. } sasl_server_params_t;
  511. /* logging levels (more levels may be added later, if necessary):
  512. */
  513. #define SASL_LOG_NONE 0 /* don't log anything */
  514. #define SASL_LOG_ERR 1 /* log unusual errors (default) */
  515. #define SASL_LOG_FAIL 2 /* log all authentication failures */
  516. #define SASL_LOG_WARN 3 /* log non-fatal warnings */
  517. #define SASL_LOG_NOTE 4 /* more verbose than LOG_WARN */
  518. #define SASL_LOG_DEBUG 5 /* more verbose than LOG_NOTE */
  519. #define SASL_LOG_TRACE 6 /* traces of internal protocols */
  520. #define SASL_LOG_PASS 7 /* traces of internal protocols, including
  521. * passwords */
  522. /* additional flags for setpass() function below:
  523. */
  524. /* SASL_SET_CREATE create user if pass non-NULL */
  525. /* SASL_SET_DISABLE disable user */
  526. #define SASL_SET_REMOVE SASL_SET_CREATE /* remove user if pass is NULL */
  527. /* features for server plug-in
  528. */
  529. #define SASL_FEAT_SERVICE 0x0200 /* service-specific passwords supported */
  530. #define SASL_FEAT_GETSECRET 0x0400 /* sasl_server_{get,put}secret_t callbacks
  531. * required by plug-in */
  532. /* a C object for a server mechanism
  533. */
  534. typedef struct sasl_server_plug {
  535. /* mechanism name */
  536. const char *mech_name;
  537. /* best mech additional security layer strength factor */
  538. sasl_ssf_t max_ssf;
  539. /* best security flags, as defined in sasl_security_properties_t */
  540. unsigned security_flags;
  541. /* features of plugin */
  542. unsigned features;
  543. /* global state for mechanism */
  544. void *glob_context;
  545. /* create a new mechanism handler
  546. * glob_context -- global context
  547. * sparams -- server config params
  548. * challenge -- server challenge from previous instance or NULL
  549. * challen -- length of challenge from previous instance or 0
  550. * out:
  551. * conn_context -- connection context
  552. * errinfo -- error information
  553. *
  554. * returns:
  555. * SASL_OK -- successfully created mech instance
  556. * SASL_* -- any other server error code
  557. */
  558. int (*mech_new)(void *glob_context,
  559. sasl_server_params_t *sparams,
  560. const char *challenge,
  561. unsigned challen,
  562. void **conn_context);
  563. /* perform one step in exchange
  564. *
  565. * returns:
  566. * SASL_OK -- success, all done
  567. * SASL_CONTINUE -- success, one more round trip
  568. * SASL_* -- any other server error code
  569. */
  570. int (*mech_step)(void *conn_context,
  571. sasl_server_params_t *sparams,
  572. const char *clientin,
  573. unsigned clientinlen,
  574. const char **serverout,
  575. unsigned *serveroutlen,
  576. sasl_out_params_t *oparams);
  577. /* dispose of a connection state
  578. */
  579. void (*mech_dispose)(void *conn_context, const sasl_utils_t *utils);
  580. /* free global state for mechanism
  581. * mech_dispose must be called on all mechanisms first
  582. */
  583. void (*mech_free)(void *glob_context, const sasl_utils_t *utils);
  584. /* set a password (optional)
  585. * glob_context -- global context
  586. * sparams -- service, middleware utilities, etc. props ignored
  587. * user -- user name
  588. * pass -- password/passphrase (NULL = disable/remove/delete)
  589. * passlen -- length of password/passphrase
  590. * oldpass -- old password/passphrase (NULL = transition)
  591. * oldpasslen -- length of password/passphrase
  592. * flags -- see above
  593. *
  594. * returns:
  595. * SASL_NOCHANGE -- no change was needed
  596. * SASL_NOUSER -- no entry for user
  597. * SASL_NOVERIFY -- no mechanism compatible entry for user
  598. * SASL_PWLOCK -- password locked
  599. * SASL_DIABLED -- account disabled
  600. * etc.
  601. */
  602. int (*setpass)(void *glob_context,
  603. sasl_server_params_t *sparams,
  604. const char *user,
  605. const char *pass, unsigned passlen,
  606. const char *oldpass, unsigned oldpasslen,
  607. unsigned flags);
  608. /* query which mechanisms are available for user
  609. * glob_context -- context
  610. * sparams -- service, middleware utilities, etc. props ignored
  611. * user -- NUL terminated user name
  612. * maxmech -- max number of strings in mechlist (0 = no output)
  613. * output:
  614. * mechlist -- an array of C string pointers, filled in with
  615. * mechanism names available to the user
  616. *
  617. * returns:
  618. * SASL_OK -- success
  619. * SASL_NOMEM -- not enough memory
  620. * SASL_FAIL -- lower level failure
  621. * SASL_DISABLED -- account disabled
  622. * SASL_NOUSER -- user not found
  623. * SASL_BUFOVER -- maxmech is too small
  624. * SASL_NOVERIFY -- user found, but no mechanisms available
  625. */
  626. int (*user_query)(void *glob_context,
  627. sasl_server_params_t *sparams,
  628. const char *user,
  629. int maxmech,
  630. const char **mechlist);
  631. /* perform precalculations during a network round-trip
  632. * or idle period. conn_context may be NULL (optional)
  633. * returns 1 if action taken, 0 if no action taken
  634. */
  635. int (*idle)(void *glob_context,
  636. void *conn_context,
  637. sasl_server_params_t *sparams);
  638. /* check if mechanism is available
  639. * optional--if NULL, mechanism is available based on ENABLE= in config
  640. *
  641. * If this routine sets conn_context to a non-NULL value, then the call
  642. * to mech_new will be skipped. This should not be done unless
  643. * there's a significant performance benefit, since it can cause
  644. * additional memory allocation in SASL core code to keep track of
  645. * contexts potentially for multiple mechanisms.
  646. *
  647. * This is called by the first call to sasl_listmech() for a
  648. * given connection context, thus for a given protocol it may
  649. * never be called. Note that if mech_avail returns SASL_NOMECH,
  650. * then that mechanism is considered disabled for the remainder
  651. * of the session. If mech_avail returns SASL_NOTDONE, then a
  652. * future call to mech_avail may still return either SASL_OK
  653. * or SASL_NOMECH.
  654. *
  655. * returns SASL_OK on success,
  656. * SASL_NOTDONE if mech is not available now, but may be later
  657. * (e.g. EXTERNAL w/o auth_id)
  658. * SASL_NOMECH if mech disabled
  659. */
  660. int (*mech_avail)(void *glob_context,
  661. sasl_server_params_t *sparams,
  662. void **conn_context);
  663. /* for additions which don't require a version upgrade; set to 0 */
  664. int (*spare_fptr2)(void);
  665. } sasl_server_plug_t;
  666. #define SASL_SERVER_PLUG_VERSION 4
  667. /* plug-in entry point:
  668. * utils -- utility callback functions
  669. * plugname -- name of plug-in (may be NULL)
  670. * max_version -- highest server plug version supported
  671. * returns:
  672. * out_version -- server plug-in version of result
  673. * pluglist -- list of mechanism plug-ins
  674. * plugcount -- number of mechanism plug-ins
  675. * results:
  676. * SASL_OK -- success
  677. * SASL_NOMEM -- failure
  678. * SASL_BADVERS -- max_version too small
  679. * SASL_BADPARAM -- bad config string
  680. * ...
  681. */
  682. typedef int sasl_server_plug_init_t(const sasl_utils_t *utils,
  683. int max_version,
  684. int *out_version,
  685. sasl_server_plug_t **pluglist,
  686. int *plugcount);
  687. /*
  688. * add a server plug-in
  689. */
  690. LIBSASL_API int sasl_server_add_plugin(const char *plugname,
  691. sasl_server_plug_init_t *splugfunc);
  692. typedef struct server_sasl_mechanism
  693. {
  694. int version;
  695. int condition; /* set to SASL_NOUSER if no available users;
  696. set to SASL_CONTINUE if delayed plugin loading */
  697. char *plugname; /* for AUTHSOURCE tracking */
  698. const sasl_server_plug_t *plug;
  699. char *f; /* where should i load the mechanism from? */
  700. } server_sasl_mechanism_t;
  701. typedef void sasl_server_info_callback_t (server_sasl_mechanism_t *m,
  702. sasl_info_callback_stage_t stage,
  703. void *rock);
  704. /* Dump information about available server plugins (separate functions are
  705. used for canon and auxprop plugins) */
  706. LIBSASL_API int sasl_server_plugin_info (const char *mech_list,
  707. sasl_server_info_callback_t *info_cb,
  708. void *info_cb_rock);
  709. /*********************************************************
  710. * user canonicalization plug-in -- added cjn 1999-09-29 *
  711. *********************************************************/
  712. typedef struct sasl_canonuser {
  713. /* optional features of plugin (set to 0) */
  714. int features;
  715. /* spare integer (set to 0) */
  716. int spare_int1;
  717. /* global state for plugin */
  718. void *glob_context;
  719. /* name of plugin */
  720. char *name;
  721. /* free global state for plugin */
  722. void (*canon_user_free)(void *glob_context, const sasl_utils_t *utils);
  723. /* canonicalize a username
  724. * glob_context -- global context from this structure
  725. * sparams -- server params, note user_realm&propctx elements
  726. * user -- user to login as (may not be NUL terminated)
  727. * len -- length of user name (0 = strlen(user))
  728. * flags -- for SASL_CU_* flags
  729. * out -- buffer to copy user name
  730. * out_max -- max length of user name
  731. * out_len -- set to length of user name
  732. *
  733. * note that the output buffers MAY be the same as the input buffers.
  734. *
  735. * returns
  736. * SASL_OK on success
  737. * SASL_BADPROT username contains invalid character
  738. */
  739. int (*canon_user_server)(void *glob_context,
  740. sasl_server_params_t *sparams,
  741. const char *user, unsigned len,
  742. unsigned flags,
  743. char *out,
  744. unsigned out_umax, unsigned *out_ulen);
  745. int (*canon_user_client)(void *glob_context,
  746. sasl_client_params_t *cparams,
  747. const char *user, unsigned len,
  748. unsigned flags,
  749. char *out,
  750. unsigned out_max, unsigned *out_len);
  751. /* for additions which don't require a version upgrade; set to 0 */
  752. int (*spare_fptr1)(void);
  753. int (*spare_fptr2)(void);
  754. int (*spare_fptr3)(void);
  755. } sasl_canonuser_plug_t;
  756. #define SASL_CANONUSER_PLUG_VERSION 5
  757. /* default name for canonuser plug-in entry point is "sasl_canonuser_init"
  758. * similar to sasl_server_plug_init model, except only returns one
  759. * sasl_canonuser_plug_t structure;
  760. */
  761. typedef int sasl_canonuser_init_t(const sasl_utils_t *utils,
  762. int max_version,
  763. int *out_version,
  764. sasl_canonuser_plug_t **plug,
  765. const char *plugname);
  766. /* add a canonuser plugin
  767. */
  768. LIBSASL_API int sasl_canonuser_add_plugin(const char *plugname,
  769. sasl_canonuser_init_t *canonuserfunc);
  770. /******************************************************
  771. * auxiliary property plug-in -- added cjn 1999-09-29 *
  772. ******************************************************/
  773. typedef struct sasl_auxprop_plug {
  774. /* optional features of plugin (none defined yet, set to 0) */
  775. int features;
  776. /* spare integer, must be set to 0 */
  777. int spare_int1;
  778. /* global state for plugin */
  779. void *glob_context;
  780. /* free global state for plugin (OPTIONAL) */
  781. void (*auxprop_free)(void *glob_context, const sasl_utils_t *utils);
  782. /* fill in fields of an auxiliary property context
  783. * last element in array has id of SASL_AUX_END
  784. * elements with non-0 len should be ignored.
  785. */
  786. int (*auxprop_lookup)(void *glob_context,
  787. sasl_server_params_t *sparams,
  788. unsigned flags,
  789. const char *user, unsigned ulen);
  790. /* name of the auxprop plugin */
  791. char *name;
  792. /* store the fields/values of an auxiliary property context (OPTIONAL)
  793. *
  794. * if ctx is NULL, just check if storing properties is enabled
  795. *
  796. * returns
  797. * SASL_OK on success
  798. * SASL_FAIL on failure
  799. */
  800. int (*auxprop_store)(void *glob_context,
  801. sasl_server_params_t *sparams,
  802. struct propctx *ctx,
  803. const char *user, unsigned ulen);
  804. } sasl_auxprop_plug_t;
  805. /* auxprop lookup flags */
  806. #define SASL_AUXPROP_OVERRIDE 0x01 /* if clear, ignore auxiliary properties
  807. * with non-zero len field. If set,
  808. * override value of those properties */
  809. #define SASL_AUXPROP_AUTHZID 0x02 /* if clear, we are looking up the
  810. * authid flags (prefixed with *), otherwise
  811. * we are looking up the authzid flags
  812. * (no prefix) */
  813. /* NOTE: Keep in sync with SASL_CU_<XXX> flags */
  814. #define SASL_AUXPROP_VERIFY_AGAINST_HASH 0x10
  815. #define SASL_AUXPROP_PLUG_VERSION 8
  816. /* default name for auxprop plug-in entry point is "sasl_auxprop_init"
  817. * similar to sasl_server_plug_init model, except only returns one
  818. * sasl_auxprop_plug_t structure;
  819. */
  820. typedef int sasl_auxprop_init_t(const sasl_utils_t *utils,
  821. int max_version,
  822. int *out_version,
  823. sasl_auxprop_plug_t **plug,
  824. const char *plugname);
  825. /* add an auxiliary property plug-in
  826. */
  827. LIBSASL_API int sasl_auxprop_add_plugin(const char *plugname,
  828. sasl_auxprop_init_t *auxpropfunc);
  829. typedef void auxprop_info_callback_t (sasl_auxprop_plug_t *m,
  830. sasl_info_callback_stage_t stage,
  831. void *rock);
  832. /* Dump information about available auxprop plugins (separate functions are
  833. used for canon and server authentication plugins) */
  834. LIBSASL_API int auxprop_plugin_info (const char *mech_list,
  835. auxprop_info_callback_t *info_cb,
  836. void *info_cb_rock);
  837. #ifdef __cplusplus
  838. }
  839. #endif
  840. #endif /* SASLPLUG_H */