~ubuntu-branches/ubuntu/breezy/pam/breezy

« back to all changes in this revision

Viewing changes to Linux-PAM/modules/pam_debug/pam_debug.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2004-06-28 14:28:08 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040628142808-adikk7vtfg3pzcjw
Tags: 0.76-22
* Add uploaders
* Document location of repository
* Fix options containing arguments in pam_unix, Closes: #254904

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* pam_permit module */
 
2
 
 
3
/*
 
4
 * $Id: pam_debug.c,v 1.1 2002/09/15 20:08:45 hartmans Exp $
 
5
 *
 
6
 * Written by Andrew Morgan <morgan@kernel.org> 2001/02/04
 
7
 *
 
8
 */
 
9
 
 
10
#define DEFAULT_USER "nobody"
 
11
 
 
12
#include <stdio.h>
 
13
 
 
14
/*
 
15
 * This module is intended as a debugging aide for determining how
 
16
 * the PAM stack is operating.
 
17
 *
 
18
 * here, we make definitions for the externally accessible functions
 
19
 * in this file (these definitions are required for static modules
 
20
 * but strongly encouraged generally) they are used to instruct the
 
21
 * modules include file to define their prototypes.
 
22
 */
 
23
 
 
24
#define PAM_SM_AUTH
 
25
#define PAM_SM_ACCOUNT
 
26
#define PAM_SM_SESSION
 
27
#define PAM_SM_PASSWORD
 
28
 
 
29
#include <security/pam_modules.h>
 
30
#include <security/_pam_macros.h>
 
31
 
 
32
#define _PAM_ACTION_UNDEF (-10)
 
33
#include "../../libpam/pam_tokens.h"
 
34
 
 
35
/* --- authentication management functions --- */
 
36
 
 
37
static int state(pam_handle_t *pamh, const char *text)
 
38
{
 
39
    int retval;
 
40
    struct pam_conv *conv;
 
41
    struct pam_message msg[1], *mesg[1];
 
42
    struct pam_response *response;
 
43
 
 
44
    retval = pam_get_item(pamh, PAM_CONV, (const void **)&conv);
 
45
    if ((retval != PAM_SUCCESS) || (conv == NULL)) {
 
46
        D(("failed to obtain conversation function"));
 
47
        return PAM_ABORT;
 
48
    }
 
49
 
 
50
    msg[0].msg_style = PAM_TEXT_INFO;
 
51
    msg[0].msg = text;
 
52
    mesg[0] = &msg[0];
 
53
 
 
54
    retval = conv->conv(1, (const struct pam_message **) mesg,
 
55
                        &response, conv->appdata_ptr);
 
56
    if (retval != PAM_SUCCESS) {
 
57
        D(("conversation failed"));
 
58
    }
 
59
 
 
60
    return retval;
 
61
}
 
62
 
 
63
static int parse_args(int retval, const char *event,
 
64
                      pam_handle_t *pamh, int argc, const char **argv)
 
65
{
 
66
    int i;
 
67
 
 
68
    for (i=0; i<argc; ++i) {
 
69
        int length = strlen(event);
 
70
        if (!strncmp(event, argv[i], length) && (argv[i][length] == '=')) {
 
71
            int j;
 
72
            const char *return_string = argv[i] + (length+1);
 
73
 
 
74
            for (j=0; j<_PAM_RETURN_VALUES; ++j) {
 
75
                if (!strcmp(return_string, _pam_token_returns[j])) {
 
76
                    retval = j;
 
77
                    state(pamh, argv[i]);
 
78
                    break;
 
79
                }
 
80
            }
 
81
            break;
 
82
        }
 
83
    }
 
84
 
 
85
    return retval;
 
86
}
 
87
 
 
88
PAM_EXTERN
 
89
int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
 
90
                        const char **argv)
 
91
{
 
92
    int retval;
 
93
    const char *user=NULL;
 
94
 
 
95
    /*
 
96
     * authentication requires we know who the user wants to be
 
97
     */
 
98
    retval = pam_get_user(pamh, &user, NULL);
 
99
    if (retval != PAM_SUCCESS) {
 
100
        D(("get user returned error: %s", pam_strerror(pamh,retval)));
 
101
        return retval;
 
102
    }
 
103
    if (user == NULL || *user == '\0') {
 
104
        D(("username not known"));
 
105
        pam_set_item(pamh, PAM_USER, (const void *) DEFAULT_USER);
 
106
    }
 
107
    user = NULL;                                            /* clean up */
 
108
 
 
109
    retval = parse_args(PAM_SUCCESS, "auth", pamh, argc, argv);
 
110
 
 
111
    return retval;
 
112
}
 
113
 
 
114
PAM_EXTERN
 
115
int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, 
 
116
                   const char **argv)
 
117
{
 
118
    return parse_args(PAM_SUCCESS, "cred", pamh, argc, argv);
 
119
}
 
120
 
 
121
/* --- account management functions --- */
 
122
 
 
123
PAM_EXTERN
 
124
int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc,
 
125
                     const char **argv)
 
126
{
 
127
    return parse_args(PAM_SUCCESS, "acct", pamh, argc, argv);
 
128
}
 
129
 
 
130
/* --- password management --- */
 
131
 
 
132
PAM_EXTERN
 
133
int pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc,
 
134
                     const char **argv)
 
135
{
 
136
    if (flags & PAM_PRELIM_CHECK) {
 
137
        return parse_args(PAM_SUCCESS, "prechauthtok", pamh, argc, argv);
 
138
    } else {
 
139
        return parse_args(PAM_SUCCESS, "chauthtok", pamh, argc, argv);
 
140
    }
 
141
}
 
142
 
 
143
/* --- session management --- */
 
144
 
 
145
PAM_EXTERN
 
146
int pam_sm_open_session(pam_handle_t *pamh,int flags,int argc,
 
147
                        const char **argv)
 
148
{
 
149
    return parse_args(PAM_SUCCESS, "open_session", pamh, argc, argv);
 
150
}
 
151
 
 
152
PAM_EXTERN
 
153
int pam_sm_close_session(pam_handle_t *pamh,int flags,int argc
 
154
                         ,const char **argv)
 
155
{
 
156
    return parse_args(PAM_SUCCESS, "close_session", pamh, argc, argv);
 
157
}
 
158
 
 
159
/* end of module definition */
 
160
 
 
161
#ifdef PAM_STATIC
 
162
 
 
163
/* static module data */
 
164
 
 
165
struct pam_module _pam_permit_modstruct = {
 
166
    "pam_debug",
 
167
    pam_sm_authenticate,
 
168
    pam_sm_setcred,
 
169
    pam_sm_acct_mgmt,
 
170
    pam_sm_open_session,
 
171
    pam_sm_close_session,
 
172
    pam_sm_chauthtok
 
173
};
 
174
 
 
175
#endif