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
,
61 void *application_data
)
63 ctx
->application_data
= application_data
;
67 * gsasl_application_data_get:
68 * @ctx: libgsasl handle.
70 * Retrieve application specific data from libgsasl handle. The
71 * application data is set using gsasl_application_data_set(). It is
72 * normally used by the application to maintain state between the main
73 * program and the callback.
75 * Return value: Returns the application specific data, or NULL.
78 gsasl_application_data_get (Gsasl_ctx
*ctx
)
80 return ctx
->application_data
;
84 * gsasl_client_application_data_set:
85 * @xctx: libgsasl client handle.
86 * @application_data: opaque pointer to application specific data.
88 * Store application specific data in the libgsasl client handle. The
89 * application data can be later (for instance, inside a callback) be
90 * retrieved by calling gsasl_client_application_data_get(). It is
91 * normally used by the application to maintain state between the main
92 * program and the callback.
95 gsasl_client_application_data_set (Gsasl_session_ctx
*cctx
,
96 void *application_data
)
98 cctx
->application_data
= application_data
;
102 * gsasl_client_application_data_get:
103 * @xctx: libgsasl client handle.
105 * Retrieve application specific data from libgsasl client handle. The
106 * application data is set using gsasl_client_application_data_set().
107 * It is normally used by the application to maintain state between
108 * the main program and the callback.
110 * Return value: Returns the application specific data, or NULL.
113 gsasl_client_application_data_get (Gsasl_session_ctx
*cctx
)
115 return cctx
->application_data
;
119 * gsasl_server_application_data_set:
120 * @xctx: libgsasl server handle.
121 * @application_data: opaque pointer to application specific data.
123 * Store application specific data in the libgsasl server handle. The
124 * application data can be later (for instance, inside a callback) be
125 * retrieved by calling gsasl_server_application_data_get(). It is
126 * normally used by the application to maintain state between the main
127 * program and the callback.
130 gsasl_server_application_data_set (Gsasl_session_ctx
*sctx
,
131 void *application_data
)
133 sctx
->application_data
= application_data
;
137 * gsasl_server_application_data_get:
138 * @xctx: libgsasl server handle.
140 * Retrieve application specific data from libgsasl server handle. The
141 * application data is set using gsasl_server_application_data_set().
142 * It is normally used by the application to maintain state between
143 * the main program and the callback.
145 * Return value: Returns the application specific data, or NULL.
148 gsasl_server_application_data_get (Gsasl_session_ctx
*sctx
)
150 return sctx
->application_data
;
156 ************************* Client Callbacks
162 * gsasl_client_callback_authentication_id_set:
163 * @ctx: libgsasl handle.
164 * @cb: callback function
166 * Specify the callback function to use in the client to set the
167 * authentication identity. The function can be later retrieved using
168 * gsasl_client_callback_authentication_id_get().
171 gsasl_client_callback_authentication_id_set (Gsasl_ctx
*ctx
,
172 Gsasl_client_callback_authentication_id cb
)
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 cb
)
203 ctx
->cbc_authorization_id
= cb
;
207 * gsasl_client_callback_authorization_id_get:
208 * @ctx: libgsasl handle.
210 * Return the callback earlier set by calling
211 * gsasl_client_callback_authorization_id_set().
213 Gsasl_client_callback_authorization_id
214 gsasl_client_callback_authorization_id_get (Gsasl_ctx
*ctx
)
216 return ctx
->cbc_authorization_id
;
220 * gsasl_client_callback_password_set:
221 * @ctx: libgsasl handle.
222 * @cb: callback function
224 * Specify the callback function to use in the client to set the
225 * password. The function can be later retrieved using
226 * gsasl_client_callback_password_get().
229 gsasl_client_callback_password_set (Gsasl_ctx
*ctx
,
230 Gsasl_client_callback_password cb
)
232 ctx
->cbc_password
= cb
;
237 * gsasl_client_callback_password_get:
238 * @ctx: libgsasl handle.
240 * Return the callback earlier set by calling
241 * gsasl_client_callback_password_set().
243 Gsasl_client_callback_password
244 gsasl_client_callback_password_get (Gsasl_ctx
*ctx
)
246 return ctx
->cbc_password
;
250 * gsasl_client_callback_passcode_set:
251 * @ctx: libgsasl handle.
252 * @cb: callback function
254 * Specify the callback function to use in the client to set the
255 * passcode. The function can be later retrieved using
256 * gsasl_client_callback_passcode_get().
259 gsasl_client_callback_passcode_set (Gsasl_ctx
*ctx
,
260 Gsasl_client_callback_passcode cb
)
262 ctx
->cbc_passcode
= cb
;
267 * gsasl_client_callback_passcode_get:
268 * @ctx: libgsasl handle.
270 * Return the callback earlier set by calling
271 * gsasl_client_callback_passcode_set().
273 Gsasl_client_callback_passcode
274 gsasl_client_callback_passcode_get (Gsasl_ctx
*ctx
)
276 return ctx
->cbc_passcode
;
280 * gsasl_client_callback_pin_set:
281 * @ctx: libgsasl handle.
282 * @cb: callback function
284 * Specify the callback function to use in the client to chose a new
285 * pin, possibly suggested by the server, for the SECURID mechanism.
286 * This is not normally invoked, but only when the server requests it.
287 * The function can be later retrieved using
288 * gsasl_client_callback_pin_get().
291 gsasl_client_callback_pin_set (Gsasl_ctx
*ctx
,
292 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
,
384 Gsasl_client_callback_qop cb
)
390 * gsasl_client_callback_qop_get:
391 * @ctx: libgsasl handle.
393 * Return the callback earlier set by calling
394 * gsasl_client_callback_qop_set().
396 Gsasl_client_callback_qop
397 gsasl_client_callback_qop_get (Gsasl_ctx
*ctx
)
403 * gsasl_client_callback_maxbuf_set:
404 * @ctx: libgsasl handle.
405 * @cb: callback function
407 * Specify the callback function to use in the client to inform the
408 * server of the largest buffer the client is able to receive when
409 * using the DIGEST-MD5 "auth-int" or "auth-conf" Quality of
410 * Protection (qop). If this directive is missing, the default value
411 * 65536 will be assumed. The function can be later retrieved using
412 * gsasl_client_callback_maxbuf_get().
415 gsasl_client_callback_maxbuf_set (Gsasl_ctx
*ctx
,
416 Gsasl_client_callback_maxbuf cb
)
418 ctx
->cbc_maxbuf
= cb
;
422 * gsasl_client_callback_maxbuf_get:
423 * @ctx: libgsasl handle.
425 * Return the callback earlier set by calling
426 * gsasl_client_callback_maxbuf_set().
428 Gsasl_client_callback_maxbuf
429 gsasl_client_callback_maxbuf_get (Gsasl_ctx
*ctx
)
431 return ctx
->cbc_maxbuf
;
437 ************************* Server Callbacks
443 * gsasl_server_callback_validate_set:
444 * @ctx: libgsasl handle.
445 * @cb: callback function
447 * Specify the callback function to use in the server for deciding if
448 * user is authenticated using authentication identity, authorization
449 * identity and password. The function can be later retrieved using
450 * gsasl_server_callback_validate_get().
453 gsasl_server_callback_validate_set (Gsasl_ctx
*ctx
,
454 Gsasl_server_callback_validate cb
)
456 ctx
->cbs_validate
= cb
;
460 * gsasl_server_callback_validate_get:
461 * @ctx: libgsasl handle.
463 * Return the callback earlier set by calling
464 * gsasl_server_callback_validate_set().
466 Gsasl_server_callback_validate
467 gsasl_server_callback_validate_get (Gsasl_ctx
*ctx
)
469 return ctx
->cbs_validate
;
473 * gsasl_server_callback_retrieve_set:
474 * @ctx: libgsasl handle.
475 * @cb: callback function
477 * Specify the callback function to use in the server for deciding if
478 * user is authenticated using authentication identity, authorization
479 * identity and password. The function can be later retrieved using
480 * gsasl_server_callback_retrieve_get().
483 gsasl_server_callback_retrieve_set (Gsasl_ctx
*ctx
,
484 Gsasl_server_callback_retrieve cb
)
486 ctx
->cbs_retrieve
= cb
;
490 * gsasl_server_callback_retrieve_get:
491 * @ctx: libgsasl handle.
493 * Return the callback earlier set by calling
494 * gsasl_server_callback_retrieve_set().
496 Gsasl_server_callback_retrieve
497 gsasl_server_callback_retrieve_get (Gsasl_ctx
*ctx
)
499 return ctx
->cbs_retrieve
;
503 * gsasl_server_callback_cram_md5_set:
504 * @ctx: libgsasl handle.
505 * @cb: callback function
507 * Specify the callback function to use in the server for deciding if
508 * user is authenticated using CRAM-MD5 challenge and response. The
509 * function can be later retrieved using
510 * gsasl_server_callback_cram_md5_get().
513 gsasl_server_callback_cram_md5_set (Gsasl_ctx
*ctx
,
514 Gsasl_server_callback_cram_md5 cb
)
516 ctx
->cbs_cram_md5
= cb
;
520 * gsasl_server_callback_cram_md5_get:
521 * @ctx: libgsasl handle.
523 * Return the callback earlier set by calling
524 * gsasl_server_callback_cram_md5_set().
526 Gsasl_server_callback_cram_md5
527 gsasl_server_callback_cram_md5_get (Gsasl_ctx
*ctx
)
529 return ctx
->cbs_cram_md5
;
533 * gsasl_server_callback_digest_md5_set:
534 * @ctx: libgsasl handle.
535 * @cb: callback function
537 * Specify the callback function to use in the server for retrieving
538 * the secret hash of the username, realm and password for use in the
539 * DIGEST-MD5 mechanism. The function can be later retrieved using
540 * gsasl_server_callback_digest_md5_get().
543 gsasl_server_callback_digest_md5_set (Gsasl_ctx
*ctx
,
544 Gsasl_server_callback_digest_md5 cb
)
546 ctx
->cbs_digest_md5
= cb
;
550 * gsasl_server_callback_digest_md5_get:
551 * @ctx: libgsasl handle.
553 * Return the callback earlier set by calling
554 * gsasl_server_callback_digest_md5_set().
556 Gsasl_server_callback_digest_md5
557 gsasl_server_callback_digest_md5_get (Gsasl_ctx
*ctx
)
559 return ctx
->cbs_digest_md5
;
563 * gsasl_server_callback_external_set:
564 * @ctx: libgsasl handle.
565 * @cb: callback function
567 * Specify the callback function to use in the server for deciding if
568 * user is authenticated out of band. The function can be later
569 * retrieved using gsasl_server_callback_external_get().
572 gsasl_server_callback_external_set (Gsasl_ctx
*ctx
,
573 Gsasl_server_callback_external cb
)
575 ctx
->cbs_external
= cb
;
579 * gsasl_server_callback_external_get:
580 * @ctx: libgsasl handle.
582 * Return the callback earlier set by calling
583 * gsasl_server_callback_external_set().
585 Gsasl_server_callback_external
586 gsasl_server_callback_external_get (Gsasl_ctx
*ctx
)
588 return ctx
->cbs_external
;
592 * gsasl_server_callback_anonymous_set:
593 * @ctx: libgsasl handle.
594 * @cb: callback function
596 * Specify the callback function to use in the server for deciding if
597 * user is permitted anonymous access. The function can be later
598 * retrieved using gsasl_server_callback_anonymous_get().
601 gsasl_server_callback_anonymous_set (Gsasl_ctx
*ctx
,
602 Gsasl_server_callback_anonymous cb
)
604 ctx
->cbs_anonymous
= cb
;
608 * gsasl_server_callback_anonymous_get:
609 * @ctx: libgsasl handle.
611 * Return the callback earlier set by calling
612 * gsasl_server_callback_anonymous_set().
614 Gsasl_server_callback_anonymous
615 gsasl_server_callback_anonymous_get (Gsasl_ctx
*ctx
)
617 return ctx
->cbs_anonymous
;
621 * gsasl_server_callback_realm_set:
622 * @ctx: libgsasl handle.
623 * @cb: callback function
625 * Specify the callback function to use in the server to know which
626 * realm it serves. The realm is used by the user to determine which
627 * username and password to use. The function can be later retrieved
628 * using gsasl_server_callback_realm_get().
631 gsasl_server_callback_realm_set (Gsasl_ctx
*ctx
,
632 Gsasl_server_callback_realm cb
)
638 * gsasl_server_callback_realm_get:
639 * @ctx: libgsasl handle.
641 * Return the callback earlier set by calling
642 * gsasl_server_callback_realm_set().
644 Gsasl_server_callback_realm
645 gsasl_server_callback_realm_get (Gsasl_ctx
*ctx
)
647 return ctx
->cbs_realm
;
651 * gsasl_server_callback_qop_set:
652 * @ctx: libgsasl handle.
653 * @cb: callback function
655 * Specify the callback function to use in the server to know which
656 * quality of protection it accepts. The quality of protection
657 * eventually used is selected by the client though. It is currently
658 * used by the DIGEST-MD5 mechanism. The function can be later
659 * retrieved using gsasl_server_callback_qop_get().
662 gsasl_server_callback_qop_set (Gsasl_ctx
*ctx
,
663 Gsasl_server_callback_qop cb
)
669 * gsasl_server_callback_qop_get:
670 * @ctx: libgsasl handle.
672 * Return the callback earlier set by calling
673 * gsasl_server_callback_qop_set().
675 Gsasl_server_callback_qop
676 gsasl_server_callback_qop_get (Gsasl_ctx
*ctx
)
682 * gsasl_server_callback_maxbuf_set:
683 * @ctx: libgsasl handle.
684 * @cb: callback function
686 * Specify the callback function to use in the server to inform the
687 * client of the largest buffer the server is able to receive when
688 * using the DIGEST-MD5 "auth-int" or "auth-conf" Quality of
689 * Protection (qop). If this directive is missing, the default value
690 * 65536 will be assumed. The function can be later retrieved using
691 * gsasl_server_callback_maxbuf_get().
694 gsasl_server_callback_maxbuf_set (Gsasl_ctx
*ctx
,
695 Gsasl_server_callback_maxbuf cb
)
697 ctx
->cbs_maxbuf
= cb
;
701 * gsasl_server_callback_maxbuf_get:
702 * @ctx: libgsasl handle.
704 * Return the callback earlier set by calling
705 * gsasl_server_callback_maxbuf_set().
707 Gsasl_server_callback_maxbuf
708 gsasl_server_callback_maxbuf_get (Gsasl_ctx
*ctx
)
710 return ctx
->cbs_maxbuf
;
714 * gsasl_server_callback_cipher_set:
715 * @ctx: libgsasl handle.
716 * @cb: callback function
718 * Specify the callback function to use in the server to inform the
719 * client of the cipher suites supported. The DES and 3DES ciphers
720 * must be supported for interoperability. It is currently used by
721 * the DIGEST-MD5 mechanism. The function can be later retrieved
722 * using gsasl_server_callback_cipher_get().
725 gsasl_server_callback_cipher_set (Gsasl_ctx
*ctx
,
726 Gsasl_server_callback_cipher cb
)
728 ctx
->cbs_cipher
= cb
;
732 * gsasl_server_callback_cipher_get:
733 * @ctx: libgsasl handle.
735 * Return the callback earlier set by calling
736 * gsasl_server_callback_cipher_set().
738 Gsasl_server_callback_cipher
739 gsasl_server_callback_cipher_get (Gsasl_ctx
*ctx
)
741 return ctx
->cbs_cipher
;
745 * gsasl_server_callback_securid_set:
746 * @ctx: libgsasl handle.
747 * @cb: callback function
749 * Specify the callback function to use in the server for validating a
750 * user via the SECURID mechanism. The function should return
751 * GSASL_OK if user authenticated successfully,
752 * GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE if it wants another
753 * passcode, GSASL_SECURID_SERVER_NEED_NEW_PIN if it wants a PIN
754 * change, or an error. When (and only when)
755 * GSASL_SECURID_SERVER_NEED_NEW_PIN is returned, suggestpin can be
756 * populated with a PIN code the server suggests, and suggestpinlen
757 * set to the length of the PIN. The function can be later retrieved
758 * using gsasl_server_callback_securid_get().
761 gsasl_server_callback_securid_set (Gsasl_ctx
*ctx
,
762 Gsasl_server_callback_securid cb
)
764 ctx
->cbs_securid
= cb
;
768 * gsasl_server_callback_securid_get:
769 * @ctx: libgsasl handle.
771 * Return the callback earlier set by calling
772 * gsasl_server_callback_securid_set().
774 Gsasl_server_callback_securid
775 gsasl_server_callback_securid_get (Gsasl_ctx
*ctx
)
777 return ctx
->cbs_securid
;
781 * gsasl_server_callback_gssapi_set:
782 * @ctx: libgsasl handle.
783 * @cb: callback function
785 * Specify the callback function to use in the server for checking if
786 * a GSSAPI user is authorized for username (by, e.g., calling
787 * krb5_userok()). The function should return GSASL_OK if the user
788 * should be permitted access, or an error code such as
789 * GSASL_AUTHENTICATION_ERROR on failure. The function can be later
790 * retrieved using gsasl_server_callback_gssapi_get().
793 gsasl_server_callback_gssapi_set (Gsasl_ctx
*ctx
,
794 Gsasl_server_callback_gssapi cb
)
796 ctx
->cbs_gssapi
= cb
;
800 * gsasl_server_callback_gssapi_get:
801 * @ctx: libgsasl handle.
803 * Return the callback earlier set by calling
804 * gsasl_server_callback_gssapi_set().
806 Gsasl_server_callback_gssapi
807 gsasl_server_callback_gssapi_get (Gsasl_ctx
*ctx
)
809 return ctx
->cbs_gssapi
;
813 * gsasl_server_callback_service_set:
814 * @ctx: libgsasl handle.
815 * @cb: callback function
817 * Specify the callback function to use in the server to set the name
818 * of the service. The service buffer should be a registered GSSAPI
819 * host-based service name, hostname the name of the server. The
820 * function can be later retrieved using
821 * gsasl_server_callback_service_get().
824 gsasl_server_callback_service_set (Gsasl_ctx
*ctx
,
825 Gsasl_server_callback_service cb
)
827 ctx
->cbs_service
= cb
;
831 * gsasl_server_callback_service_get:
832 * @ctx: libgsasl handle.
834 * Return the callback earlier set by calling
835 * gsasl_server_callback_service_set().
837 Gsasl_server_callback_service
838 gsasl_server_callback_service_get (Gsasl_ctx
*ctx
)
840 return ctx
->cbs_service
;