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