Initial import from FreeBSD RELENG_4:
[games.git] / contrib / libpam / libpam / pam_static.c
1 /* pam_static.c -- static module loading helper functions */
2
3 /* created by Michael K. Johnson, johnsonm@redhat.com
4  *
5  * $Id: pam_static.c,v 1.4 1996/12/01 03:14:13 morgan Exp $
6  * $FreeBSD: src/contrib/libpam/libpam/pam_static.c,v 1.2.6.2 2001/06/11 15:28:12 markm Exp $
7  *
8  * $Log: pam_static.c,v $
9  * Revision 1.4  1996/12/01 03:14:13  morgan
10  * use _pam_macros.h
11  *
12  * Revision 1.3  1996/11/10 20:09:16  morgan
13  * name convention change _pam_
14  *
15  * Revision 1.2  1996/06/02 08:02:56  morgan
16  * Michael's minor alterations
17  *
18  * Revision 1.1  1996/05/26 04:34:04  morgan
19  * Initial revision
20  *
21  */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26
27 #include "pam_private.h"
28
29 /* This whole file is only used for PAM_STATIC */
30
31 #ifdef PAM_STATIC
32
33 extern struct linker_set _pam_static_modules;
34
35 /* Return pointer to data structure used to define a static module */
36 struct pam_module * _pam_open_static_handler(char *path) {
37     int i;
38     char *lpath = path, *end;
39     struct pam_module **static_modules =
40         (struct pam_module **)_pam_static_modules.ls_items;
41
42     if (strchr(lpath, '/')) {
43         /* ignore path and leading "/" */
44         lpath = strrchr(lpath, '/') + 1;
45     }
46     /* create copy to muck with (must free before return) */
47     lpath = _pam_strdup(lpath);
48     /* chop .so off copy if it exists (or other extension on other
49        platform...) */
50     end = strstr(lpath, ".so");
51     if (end) {
52         *end = '\0';
53     }
54
55     /* now go find the module */
56     for (i = 0; static_modules[i] != NULL; i++) {
57         D(("%s=?%s\n", lpath, static_modules[i]->name));
58         if (static_modules[i]->name &&
59             ! strcmp(static_modules[i]->name, lpath)) {
60             break;
61         }
62     }
63
64     free(lpath);
65     return (static_modules[i]);
66 }
67
68 /* Return pointer to function requested from static module
69  * Can't just return void *, because ANSI C disallows casting a
70  * pointer to a function to a void *...
71  * This definition means:
72  * _pam_get_static_sym is a function taking two arguments and
73  * returning a pointer to a function which takes no arguments
74  * and returns void... */
75 voidfunc *_pam_get_static_sym(struct pam_module *mod, const char *symname) {
76
77     if (! strcmp(symname, "pam_sm_authenticate")) {
78         return ((voidfunc *)mod->pam_sm_authenticate);
79     } else if (! strcmp(symname, "pam_sm_setcred")) {
80         return ((voidfunc *)mod->pam_sm_setcred);
81     } else if (! strcmp(symname, "pam_sm_acct_mgmt")) {
82         return ((voidfunc *)mod->pam_sm_acct_mgmt);
83     } else if (! strcmp(symname, "pam_sm_open_session")) {
84         return ((voidfunc *)mod->pam_sm_open_session);
85     } else if (! strcmp(symname, "pam_sm_close_session")) {
86         return ((voidfunc *)mod->pam_sm_close_session);
87     } else if (! strcmp(symname, "pam_sm_chauthtok")) {
88         return ((voidfunc *)mod->pam_sm_chauthtok);
89     }
90     /* getting to this point is an error */
91     return ((voidfunc *)NULL);
92 }
93
94 #endif /* PAM_STATIC */
95
96 /*
97  * Copyright (C) 1995 by Red Hat Software, Michael K. Johnson
98  * All rights reserved
99  *
100  * Redistribution and use in source and binary forms, with or without
101  * modification, are permitted provided that the following conditions
102  * are met:
103  * 1. Redistributions of source code must retain the above copyright
104  *    notice, and the entire permission notice in its entirety,
105  *    including the disclaimer of warranties.
106  * 2. Redistributions in binary form must reproduce the above copyright
107  *    notice, this list of conditions and the following disclaimer in the
108  *    documentation and/or other materials provided with the distribution.
109  * 3. The name of the author may not be used to endorse or promote
110  *    products derived from this software without specific prior
111  *    written permission.
112  * 
113  * ALTERNATIVELY, this product may be distributed under the terms of
114  * the GNU Public License, in which case the provisions of the GPL are
115  * required INSTEAD OF the above restrictions.  (This clause is
116  * necessary due to a potential bad interaction between the GPL and
117  * the restrictions contained in a BSD-style copyright.)
118  * 
119  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
120  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
121  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
122  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
123  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
124  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
125  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
126  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
127  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
128  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
129  * OF THE POSSIBILITY OF SUCH DAMAGE.
130  */