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