1 /* callback.c callback handling
2 * Copyright (C) 2002 Simon Josefsson
4 * This file is part of libgsasl.
6 * Libgsasl is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libgsasl is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with libgsasl; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * gsasl_client_ctx_get:
26 * @cctx: libgsasl client handle
28 * Return value: Returns the libgsasl handle given a libgsasl client handle.
31 gsasl_client_ctx_get (Gsasl_session_ctx
* cctx
)
37 * gsasl_server_ctx_get:
38 * @cctx: libgsasl server handle
40 * Return value: Returns the libgsasl handle given a libgsasl server handle.
43 gsasl_server_ctx_get (Gsasl_session_ctx
* sctx
)
49 * gsasl_application_data_set:
50 * @ctx: libgsasl handle.
51 * @application_data: opaque pointer to application specific data.
53 * Store application specific data in the libgsasl handle. The
54 * application data can be later (for instance, inside a callback) be
55 * retrieved by calling gsasl_application_data_get(). It is normally
56 * used by the application to maintain state between the main program
60 gsasl_application_data_set (Gsasl_ctx
* ctx
, void *application_data
)
62 ctx
->application_data
= application_data
;
66 * gsasl_application_data_get:
67 * @ctx: libgsasl handle.
69 * Retrieve application specific data from libgsasl handle. The
70 * application data is set using gsasl_application_data_set(). It is
71 * normally used by the application to maintain state between the main
72 * program and the callback.
74 * Return value: Returns the application specific data, or NULL.
77 gsasl_application_data_get (Gsasl_ctx
* ctx
)
79 return ctx
->application_data
;
83 * gsasl_client_application_data_set:
84 * @xctx: libgsasl client handle.
85 * @application_data: opaque pointer to application specific data.
87 * Store application specific data in the libgsasl client handle. The
88 * application data can be later (for instance, inside a callback) be
89 * retrieved by calling gsasl_client_application_data_get(). It is
90 * normally used by the application to maintain state between the main
91 * program and the callback.
94 gsasl_client_application_data_set (Gsasl_session_ctx
* cctx
,
95 void *application_data
)
97 cctx
->application_data
= application_data
;
101 * gsasl_client_application_data_get:
102 * @xctx: libgsasl client handle.
104 * Retrieve application specific data from libgsasl client handle. The
105 * application data is set using gsasl_client_application_data_set().
106 * It is normally used by the application to maintain state between
107 * the main program and the callback.
109 * Return value: Returns the application specific data, or NULL.
112 gsasl_client_application_data_get (Gsasl_session_ctx
* cctx
)
114 return cctx
->application_data
;
118 * gsasl_server_application_data_set:
119 * @xctx: libgsasl server handle.
120 * @application_data: opaque pointer to application specific data.
122 * Store application specific data in the libgsasl server handle. The
123 * application data can be later (for instance, inside a callback) be
124 * retrieved by calling gsasl_server_application_data_get(). It is
125 * normally used by the application to maintain state between the main
126 * program and the callback.
129 gsasl_server_application_data_set (Gsasl_session_ctx
* sctx
,
130 void *application_data
)
132 sctx
->application_data
= application_data
;
136 * gsasl_server_application_data_get:
137 * @xctx: libgsasl server handle.
139 * Retrieve application specific data from libgsasl server handle. The
140 * application data is set using gsasl_server_application_data_set().
141 * It is normally used by the application to maintain state between
142 * the main program and the callback.
144 * Return value: Returns the application specific data, or NULL.
147 gsasl_server_application_data_get (Gsasl_session_ctx
* sctx
)
149 return sctx
->application_data
;
155 ************************* Client Callbacks
161 * gsasl_client_callback_authentication_id_set:
162 * @ctx: libgsasl handle.
163 * @cb: callback function
165 * Specify the callback function to use in the client to set the
166 * authentication identity. The function can be later retrieved using
167 * gsasl_client_callback_authentication_id_get().
170 gsasl_client_callback_authentication_id_set (Gsasl_ctx
* ctx
,
171 Gsasl_client_callback_authentication_id
174 ctx
->cbc_authentication_id
= cb
;
178 * gsasl_client_callback_authentication_id_get:
179 * @ctx: libgsasl handle.
181 * Return the callback earlier set by calling
182 * gsasl_client_callback_authentication_id_set().
184 Gsasl_client_callback_authentication_id
185 gsasl_client_callback_authentication_id_get (Gsasl_ctx
* ctx
)
187 return ctx
->cbc_authentication_id
;
191 * gsasl_client_callback_authorization_id_set:
192 * @ctx: libgsasl handle.
193 * @cb: callback function
195 * Specify the callback function to use in the client to set the
196 * authorization identity. The function can be later retrieved using
197 * gsasl_client_callback_authorization_id_get().
200 gsasl_client_callback_authorization_id_set (Gsasl_ctx
* ctx
,
201 Gsasl_client_callback_authorization_id
204 ctx
->cbc_authorization_id
= cb
;
208 * gsasl_client_callback_authorization_id_get:
209 * @ctx: libgsasl handle.
211 * Return the callback earlier set by calling
212 * gsasl_client_callback_authorization_id_set().
214 Gsasl_client_callback_authorization_id
215 gsasl_client_callback_authorization_id_get (Gsasl_ctx
* ctx
)
217 return ctx
->cbc_authorization_id
;
221 * gsasl_client_callback_password_set:
222 * @ctx: libgsasl handle.
223 * @cb: callback function
225 * Specify the callback function to use in the client to set the
226 * password. The function can be later retrieved using
227 * gsasl_client_callback_password_get().
230 gsasl_client_callback_password_set (Gsasl_ctx
* ctx
,
231 Gsasl_client_callback_password cb
)
233 ctx
->cbc_password
= cb
;
238 * gsasl_client_callback_password_get:
239 * @ctx: libgsasl handle.
241 * Return the callback earlier set by calling
242 * gsasl_client_callback_password_set().
244 Gsasl_client_callback_password
245 gsasl_client_callback_password_get (Gsasl_ctx
* ctx
)
247 return ctx
->cbc_password
;
251 * gsasl_client_callback_passcode_set:
252 * @ctx: libgsasl handle.
253 * @cb: callback function
255 * Specify the callback function to use in the client to set the
256 * passcode. The function can be later retrieved using
257 * gsasl_client_callback_passcode_get().
260 gsasl_client_callback_passcode_set (Gsasl_ctx
* ctx
,
261 Gsasl_client_callback_passcode cb
)
263 ctx
->cbc_passcode
= cb
;
268 * gsasl_client_callback_passcode_get:
269 * @ctx: libgsasl handle.
271 * Return the callback earlier set by calling
272 * gsasl_client_callback_passcode_set().
274 Gsasl_client_callback_passcode
275 gsasl_client_callback_passcode_get (Gsasl_ctx
* ctx
)
277 return ctx
->cbc_passcode
;
281 * gsasl_client_callback_pin_set:
282 * @ctx: libgsasl handle.
283 * @cb: callback function
285 * Specify the callback function to use in the client to chose a new
286 * pin, possibly suggested by the server, for the SECURID mechanism.
287 * This is not normally invoked, but only when the server requests it.
288 * The function can be later retrieved using
289 * gsasl_client_callback_pin_get().
292 gsasl_client_callback_pin_set (Gsasl_ctx
* ctx
, Gsasl_client_callback_pin cb
)
299 * gsasl_client_callback_pin_get:
300 * @ctx: libgsasl handle.
302 * Return the callback earlier set by calling
303 * gsasl_client_callback_pin_set().
305 Gsasl_client_callback_pin
306 gsasl_client_callback_pin_get (Gsasl_ctx
* ctx
)
312 * gsasl_client_callback_service_set:
313 * @ctx: libgsasl handle.
314 * @cb: callback function
316 * Specify the callback function to use in the client to set the name
317 * of the service. The service buffer should be a registered GSSAPI
318 * host-based service name, hostname the name of the server.
319 * Servicename is used by DIGEST-MD5 and should be the name of generic
320 * server in case of a replicated service. The function can be later
321 * retrieved using gsasl_client_callback_service_get().
324 gsasl_client_callback_service_set (Gsasl_ctx
* ctx
,
325 Gsasl_client_callback_service cb
)
327 ctx
->cbc_service
= cb
;
331 * gsasl_client_callback_service_get:
332 * @ctx: libgsasl handle.
334 * Return the callback earlier set by calling
335 * gsasl_client_callback_service_set().
337 Gsasl_client_callback_service
338 gsasl_client_callback_service_get (Gsasl_ctx
* ctx
)
340 return ctx
->cbc_service
;
344 * gsasl_client_callback_anonymous_set:
345 * @ctx: libgsasl handle.
346 * @cb: callback function
348 * Specify the callback function to use in the client to set the
349 * anonymous token, which usually is the users email address. The
350 * function can be later retrieved using
351 * gsasl_client_callback_anonymous_get().
354 gsasl_client_callback_anonymous_set (Gsasl_ctx
* ctx
,
355 Gsasl_client_callback_anonymous cb
)
357 ctx
->cbc_anonymous
= cb
;
361 * gsasl_client_callback_anonymous_get:
362 * @ctx: libgsasl handle.
364 * Return the callback earlier set by calling
365 * gsasl_client_callback_anonymous_set().
367 Gsasl_client_callback_anonymous
368 gsasl_client_callback_anonymous_get (Gsasl_ctx
* ctx
)
370 return ctx
->cbc_anonymous
;
374 * gsasl_client_callback_qop_set:
375 * @ctx: libgsasl handle.
376 * @cb: callback function
378 * Specify the callback function to use in the client to determine the
379 * qop to use after looking at what the server offered. The function
380 * can be later retrieved using gsasl_client_callback_qop_get().
383 gsasl_client_callback_qop_set (Gsasl_ctx
* ctx
, Gsasl_client_callback_qop cb
)
389 * gsasl_client_callback_qop_get:
390 * @ctx: libgsasl handle.
392 * Return the callback earlier set by calling
393 * gsasl_client_callback_qop_set().
395 Gsasl_client_callback_qop
396 gsasl_client_callback_qop_get (Gsasl_ctx
* ctx
)
402 * gsasl_client_callback_maxbuf_set:
403 * @ctx: libgsasl handle.
404 * @cb: callback function
406 * Specify the callback function to use in the client to inform the
407 * server of the largest buffer the client is able to receive when
408 * using the DIGEST-MD5 "auth-int" or "auth-conf" Quality of
409 * Protection (qop). If this directive is missing, the default value
410 * 65536 will be assumed. The function can be later retrieved using
411 * gsasl_client_callback_maxbuf_get().
414 gsasl_client_callback_maxbuf_set (Gsasl_ctx
* ctx
,
415 Gsasl_client_callback_maxbuf cb
)
417 ctx
->cbc_maxbuf
= cb
;
421 * gsasl_client_callback_maxbuf_get:
422 * @ctx: libgsasl handle.
424 * Return the callback earlier set by calling
425 * gsasl_client_callback_maxbuf_set().
427 Gsasl_client_callback_maxbuf
428 gsasl_client_callback_maxbuf_get (Gsasl_ctx
* ctx
)
430 return ctx
->cbc_maxbuf
;
436 ************************* Server Callbacks
442 * gsasl_server_callback_validate_set:
443 * @ctx: libgsasl handle.
444 * @cb: callback function
446 * Specify the callback function to use in the server for deciding if
447 * user is authenticated using authentication identity, authorization
448 * identity and password. The function can be later retrieved using
449 * gsasl_server_callback_validate_get().
452 gsasl_server_callback_validate_set (Gsasl_ctx
* ctx
,
453 Gsasl_server_callback_validate cb
)
455 ctx
->cbs_validate
= cb
;
459 * gsasl_server_callback_validate_get:
460 * @ctx: libgsasl handle.
462 * Return the callback earlier set by calling
463 * gsasl_server_callback_validate_set().
465 Gsasl_server_callback_validate
466 gsasl_server_callback_validate_get (Gsasl_ctx
* ctx
)
468 return ctx
->cbs_validate
;
472 * gsasl_server_callback_retrieve_set:
473 * @ctx: libgsasl handle.
474 * @cb: callback function
476 * Specify the callback function to use in the server for deciding if
477 * user is authenticated using authentication identity, authorization
478 * identity and password. The function can be later retrieved using
479 * gsasl_server_callback_retrieve_get().
482 gsasl_server_callback_retrieve_set (Gsasl_ctx
* ctx
,
483 Gsasl_server_callback_retrieve cb
)
485 ctx
->cbs_retrieve
= cb
;
489 * gsasl_server_callback_retrieve_get:
490 * @ctx: libgsasl handle.
492 * Return the callback earlier set by calling
493 * gsasl_server_callback_retrieve_set().
495 Gsasl_server_callback_retrieve
496 gsasl_server_callback_retrieve_get (Gsasl_ctx
* ctx
)
498 return ctx
->cbs_retrieve
;
502 * gsasl_server_callback_cram_md5_set:
503 * @ctx: libgsasl handle.
504 * @cb: callback function
506 * Specify the callback function to use in the server for deciding if
507 * user is authenticated using CRAM-MD5 challenge and response. The
508 * function can be later retrieved using
509 * gsasl_server_callback_cram_md5_get().
512 gsasl_server_callback_cram_md5_set (Gsasl_ctx
* ctx
,
513 Gsasl_server_callback_cram_md5 cb
)
515 ctx
->cbs_cram_md5
= cb
;
519 * gsasl_server_callback_cram_md5_get:
520 * @ctx: libgsasl handle.
522 * Return the callback earlier set by calling
523 * gsasl_server_callback_cram_md5_set().
525 Gsasl_server_callback_cram_md5
526 gsasl_server_callback_cram_md5_get (Gsasl_ctx
* ctx
)
528 return ctx
->cbs_cram_md5
;
532 * gsasl_server_callback_digest_md5_set:
533 * @ctx: libgsasl handle.
534 * @cb: callback function
536 * Specify the callback function to use in the server for retrieving
537 * the secret hash of the username, realm and password for use in the
538 * DIGEST-MD5 mechanism. The function can be later retrieved using
539 * gsasl_server_callback_digest_md5_get().
542 gsasl_server_callback_digest_md5_set (Gsasl_ctx
* ctx
,
543 Gsasl_server_callback_digest_md5 cb
)
545 ctx
->cbs_digest_md5
= cb
;
549 * gsasl_server_callback_digest_md5_get:
550 * @ctx: libgsasl handle.
552 * Return the callback earlier set by calling
553 * gsasl_server_callback_digest_md5_set().
555 Gsasl_server_callback_digest_md5
556 gsasl_server_callback_digest_md5_get (Gsasl_ctx
* ctx
)
558 return ctx
->cbs_digest_md5
;
562 * gsasl_server_callback_external_set:
563 * @ctx: libgsasl handle.
564 * @cb: callback function
566 * Specify the callback function to use in the server for deciding if
567 * user is authenticated out of band. The function can be later
568 * retrieved using gsasl_server_callback_external_get().
571 gsasl_server_callback_external_set (Gsasl_ctx
* ctx
,
572 Gsasl_server_callback_external cb
)
574 ctx
->cbs_external
= cb
;
578 * gsasl_server_callback_external_get:
579 * @ctx: libgsasl handle.
581 * Return the callback earlier set by calling
582 * gsasl_server_callback_external_set().
584 Gsasl_server_callback_external
585 gsasl_server_callback_external_get (Gsasl_ctx
* ctx
)
587 return ctx
->cbs_external
;
591 * gsasl_server_callback_anonymous_set:
592 * @ctx: libgsasl handle.
593 * @cb: callback function
595 * Specify the callback function to use in the server for deciding if
596 * user is permitted anonymous access. The function can be later
597 * retrieved using gsasl_server_callback_anonymous_get().
600 gsasl_server_callback_anonymous_set (Gsasl_ctx
* ctx
,
601 Gsasl_server_callback_anonymous cb
)
603 ctx
->cbs_anonymous
= cb
;
607 * gsasl_server_callback_anonymous_get:
608 * @ctx: libgsasl handle.
610 * Return the callback earlier set by calling
611 * gsasl_server_callback_anonymous_set().
613 Gsasl_server_callback_anonymous
614 gsasl_server_callback_anonymous_get (Gsasl_ctx
* ctx
)
616 return ctx
->cbs_anonymous
;
620 * gsasl_server_callback_realm_set:
621 * @ctx: libgsasl handle.
622 * @cb: callback function
624 * Specify the callback function to use in the server to know which
625 * realm it serves. The realm is used by the user to determine which
626 * username and password to use. The function can be later retrieved
627 * using gsasl_server_callback_realm_get().
630 gsasl_server_callback_realm_set (Gsasl_ctx
* ctx
,
631 Gsasl_server_callback_realm cb
)
637 * gsasl_server_callback_realm_get:
638 * @ctx: libgsasl handle.
640 * Return the callback earlier set by calling
641 * gsasl_server_callback_realm_set().
643 Gsasl_server_callback_realm
644 gsasl_server_callback_realm_get (Gsasl_ctx
* ctx
)
646 return ctx
->cbs_realm
;
650 * gsasl_server_callback_qop_set:
651 * @ctx: libgsasl handle.
652 * @cb: callback function
654 * Specify the callback function to use in the server to know which
655 * quality of protection it accepts. The quality of protection
656 * eventually used is selected by the client though. It is currently
657 * used by the DIGEST-MD5 mechanism. The function can be later
658 * retrieved using gsasl_server_callback_qop_get().
661 gsasl_server_callback_qop_set (Gsasl_ctx
* ctx
, Gsasl_server_callback_qop cb
)
667 * gsasl_server_callback_qop_get:
668 * @ctx: libgsasl handle.
670 * Return the callback earlier set by calling
671 * gsasl_server_callback_qop_set().
673 Gsasl_server_callback_qop
674 gsasl_server_callback_qop_get (Gsasl_ctx
* ctx
)
680 * gsasl_server_callback_maxbuf_set:
681 * @ctx: libgsasl handle.
682 * @cb: callback function
684 * Specify the callback function to use in the server to inform the
685 * client of the largest buffer the server is able to receive when
686 * using the DIGEST-MD5 "auth-int" or "auth-conf" Quality of
687 * Protection (qop). If this directive is missing, the default value
688 * 65536 will be assumed. The function can be later retrieved using
689 * gsasl_server_callback_maxbuf_get().
692 gsasl_server_callback_maxbuf_set (Gsasl_ctx
* ctx
,
693 Gsasl_server_callback_maxbuf cb
)
695 ctx
->cbs_maxbuf
= cb
;
699 * gsasl_server_callback_maxbuf_get:
700 * @ctx: libgsasl handle.
702 * Return the callback earlier set by calling
703 * gsasl_server_callback_maxbuf_set().
705 Gsasl_server_callback_maxbuf
706 gsasl_server_callback_maxbuf_get (Gsasl_ctx
* ctx
)
708 return ctx
->cbs_maxbuf
;
712 * gsasl_server_callback_cipher_set:
713 * @ctx: libgsasl handle.
714 * @cb: callback function
716 * Specify the callback function to use in the server to inform the
717 * client of the cipher suites supported. The DES and 3DES ciphers
718 * must be supported for interoperability. It is currently used by
719 * the DIGEST-MD5 mechanism. The function can be later retrieved
720 * using gsasl_server_callback_cipher_get().
723 gsasl_server_callback_cipher_set (Gsasl_ctx
* ctx
,
724 Gsasl_server_callback_cipher cb
)
726 ctx
->cbs_cipher
= cb
;
730 * gsasl_server_callback_cipher_get:
731 * @ctx: libgsasl handle.
733 * Return the callback earlier set by calling
734 * gsasl_server_callback_cipher_set().
736 Gsasl_server_callback_cipher
737 gsasl_server_callback_cipher_get (Gsasl_ctx
* ctx
)
739 return ctx
->cbs_cipher
;
743 * gsasl_server_callback_securid_set:
744 * @ctx: libgsasl handle.
745 * @cb: callback function
747 * Specify the callback function to use in the server for validating a
748 * user via the SECURID mechanism. The function should return
749 * GSASL_OK if user authenticated successfully,
750 * GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE if it wants another
751 * passcode, GSASL_SECURID_SERVER_NEED_NEW_PIN if it wants a PIN
752 * change, or an error. When (and only when)
753 * GSASL_SECURID_SERVER_NEED_NEW_PIN is returned, suggestpin can be
754 * populated with a PIN code the server suggests, and suggestpinlen
755 * set to the length of the PIN. The function can be later retrieved
756 * using gsasl_server_callback_securid_get().
759 gsasl_server_callback_securid_set (Gsasl_ctx
* ctx
,
760 Gsasl_server_callback_securid cb
)
762 ctx
->cbs_securid
= cb
;
766 * gsasl_server_callback_securid_get:
767 * @ctx: libgsasl handle.
769 * Return the callback earlier set by calling
770 * gsasl_server_callback_securid_set().
772 Gsasl_server_callback_securid
773 gsasl_server_callback_securid_get (Gsasl_ctx
* ctx
)
775 return ctx
->cbs_securid
;
779 * gsasl_server_callback_gssapi_set:
780 * @ctx: libgsasl handle.
781 * @cb: callback function
783 * Specify the callback function to use in the server for checking if
784 * a GSSAPI user is authorized for username (by, e.g., calling
785 * krb5_userok()). The function should return GSASL_OK if the user
786 * should be permitted access, or an error code such as
787 * GSASL_AUTHENTICATION_ERROR on failure. The function can be later
788 * retrieved using gsasl_server_callback_gssapi_get().
791 gsasl_server_callback_gssapi_set (Gsasl_ctx
* ctx
,
792 Gsasl_server_callback_gssapi cb
)
794 ctx
->cbs_gssapi
= cb
;
798 * gsasl_server_callback_gssapi_get:
799 * @ctx: libgsasl handle.
801 * Return the callback earlier set by calling
802 * gsasl_server_callback_gssapi_set().
804 Gsasl_server_callback_gssapi
805 gsasl_server_callback_gssapi_get (Gsasl_ctx
* ctx
)
807 return ctx
->cbs_gssapi
;
811 * gsasl_server_callback_service_set:
812 * @ctx: libgsasl handle.
813 * @cb: callback function
815 * Specify the callback function to use in the server to set the name
816 * of the service. The service buffer should be a registered GSSAPI
817 * host-based service name, hostname the name of the server. The
818 * function can be later retrieved using
819 * gsasl_server_callback_service_get().
822 gsasl_server_callback_service_set (Gsasl_ctx
* ctx
,
823 Gsasl_server_callback_service cb
)
825 ctx
->cbs_service
= cb
;
829 * gsasl_server_callback_service_get:
830 * @ctx: libgsasl handle.
832 * Return the callback earlier set by calling
833 * gsasl_server_callback_service_set().
835 Gsasl_server_callback_service
836 gsasl_server_callback_service_get (Gsasl_ctx
* ctx
)
838 return ctx
->cbs_service
;