1/* sasldb.h - SASLdb library header
2 * Rob Siemborski
3 * Tim Martin
4 * $Id: sasldb.h,v 1.5 2005/01/10 19:01:34 snsimon Exp $
5 */
6/*
7 * Copyright (c) 1998-2003 Carnegie Mellon University.  All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in
18 *    the documentation and/or other materials provided with the
19 *    distribution.
20 *
21 * 3. The name "Carnegie Mellon University" must not be used to
22 *    endorse or promote products derived from this software without
23 *    prior written permission. For permission or any other legal
24 *    details, please contact
25 *      Office of Technology Transfer
26 *      Carnegie Mellon University
27 *      5000 Forbes Avenue
28 *      Pittsburgh, PA  15213-3890
29 *      (412) 268-4387, fax: (412) 268-7395
30 *      tech-transfer@andrew.cmu.edu
31 *
32 * 4. Redistributions of any form whatsoever must retain the following
33 *    acknowledgment:
34 *    "This product includes software developed by Computing Services
35 *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
36 *
37 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
38 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
40 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
41 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
42 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
43 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
44 */
45
46#ifndef SASLDB_H
47#define SASLDB_H
48
49#include "sasl.h"
50#include "saslplug.h"
51
52/*
53 * Note that some of these require a sasl_conn_t in order for
54 * the getcallback stuff to work correctly.  This is great for
55 * when they are called from a plugin or the library but makes
56 * for much wierdness when an otherwise non-sasl application needs
57 * to make use of this functionality.
58 */
59
60int _sasldb_getdata(const sasl_utils_t *utils,
61		    sasl_conn_t *conn,
62		    const char *authid,
63		    const char *realm,
64		    const char *propName,
65		    char *out, const size_t max_out, size_t *out_len);
66
67/* pass NULL for data to delete it */
68int _sasldb_putdata(const sasl_utils_t *utils,
69		    sasl_conn_t *conn,
70		    const char *authid,
71		    const char *realm,
72		    const char *propName,
73		    const char *data, size_t data_len);
74
75/* Should be run before any db access is attempted */
76LIBSASL_API int _sasl_check_db(const sasl_utils_t *utils,
77		   sasl_conn_t *conn);
78
79/* These allow iterating through the keys of the database */
80typedef void* sasldb_handle;
81
82typedef int (* sasldb_list_callback_t) (const char *authid,
83				        const char *realm,
84					const char *property,
85					void *rock);
86
87LIBSASL_API sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
88				   sasl_conn_t *conn);
89LIBSASL_API int _sasldb_getnextkey(const sasl_utils_t *utils,
90		       sasldb_handle handle, char *out,
91		       const size_t max_out, size_t *out_len);
92LIBSASL_API int _sasldb_releasekeyhandle(const sasl_utils_t *utils,
93			     sasldb_handle handle);
94
95LIBSASL_API int _sasldb_listusers(const sasl_utils_t *utils,
96				  sasl_conn_t *context,
97				  sasldb_list_callback_t callback,
98				  void *callback_rock);
99
100#if defined(KEEP_DB_OPEN)
101void sasldb_auxprop_free (void *glob_context, const sasl_utils_t *utils);
102#else
103#define sasldb_auxprop_free	NULL
104#endif
105
106/* The rest are implemented in allockey.c and individual drivers need not
107 * do so */
108/* These two are aliases for getdata/putdata */
109int _sasldb_getsecret(const sasl_utils_t *utils,
110		      sasl_conn_t *context,
111		      const char *auth_identity,
112		      const char *realm,
113		      sasl_secret_t ** secret);
114
115int _sasldb_putsecret(const sasl_utils_t *utils,
116		      sasl_conn_t *context,
117		      const char *auth_identity,
118		      const char *realm,
119		      const sasl_secret_t * secret);
120
121LIBSASL_API int _sasldb_parse_key(const char *key, const size_t key_len,
122		      char *authid, const size_t max_authid,
123		      char *realm, const size_t max_realm,
124		      char *propName, const size_t max_propname);
125
126/* This function is internal, but might be useful to have around */
127int _sasldb_alloc_key(const sasl_utils_t *utils,
128		      const char *auth_identity,
129		      const char *realm,
130		      const char *propName,
131		      char **key,
132		      size_t *key_len);
133
134#endif /* SASLDB_H */
135