~ubuntu-branches/ubuntu/raring/sudo/raring

« back to all changes in this revision

Viewing changes to plugins/sudoers/auth/sudo_auth.c

  • Committer: Package Import Robot
  • Author(s): Tyler Hicks
  • Date: 2012-07-16 14:01:42 UTC
  • mfrom: (1.3.22 sid)
  • Revision ID: package-import@ubuntu.com-20120716140142-b0tgau0k6nid4mrf
Tags: 1.8.5p2-1ubuntu1
* Merge from debian/testing (LP: #1024154), remaining changes:
  - debian/patches/keep_home_by_default.patch:
    + Set HOME in initial_keepenv_table.
  - debian/rules:
    + compile with --without-lecture --with-tty-tickets (Ubuntu specific)
    + install man/man8/sudo_root.8 in both flavours (Ubuntu specific)
    + install apport hooks
    + The ubuntu-sudo-as-admin-successful.patch was taken upstream by
      Debian however it requires a --enable-admin-flag configure flag to
      actually enable it in both flavours.
  - debian/control:
    + Mark Debian Vcs-* as XS-Debian-Vcs-*
    + update debian/control
  - debian/sudoers:
    + grant admin group sudo access
  - debian/source_sudo.py, debian/sudo-ldap.dirs, debian/sudo.dirs:
    + add usr/share/apport/package-hooks
  - debian/sudo.pam:
    + Use pam_env to read /etc/environment and /etc/default/locale
      environment files. Reading ~/.pam_environment is not permitted due to
      security reasons.
* Dropped changes:
  - debian/patches/lp927828-fix-abort-in-pam-modules-when-timestamp-valid.patch
    + Fixed upstream in 1.8.5
  - debian/patches/CVE-2012-2337.patch:
    + Fixed upstream in 1.8.4p5
  - debian/patches/pam_env_merge.patch:
    + Feature released upstream in 1.8.5
  - debian/{sudo,sudo-ldap}.{preinst,postinst,postrm}:
    + Drop Ubuntu-specific sudoers file migration code because the only
      upgrade path to quantal is from precise. All necessary sudoers file
      migration will have already been done by the time this version of the
      sudo package is installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
static sudo_auth auth_switch[] = {
52
52
/* Standalone entries first */
53
53
#ifdef HAVE_PAM
54
 
    AUTH_ENTRY("pam", FLAG_STANDALONE, pam_init, NULL, pam_verify, pam_cleanup, pam_begin_session, pam_end_session)
 
54
    AUTH_ENTRY("pam", FLAG_STANDALONE, sudo_pam_init, NULL, sudo_pam_verify, sudo_pam_cleanup, sudo_pam_begin_session, sudo_pam_end_session)
55
55
#endif
56
56
#ifdef HAVE_SECURID
57
 
    AUTH_ENTRY("SecurId", FLAG_STANDALONE, securid_init, securid_setup, securid_verify, NULL, NULL, NULL)
 
57
    AUTH_ENTRY("SecurId", FLAG_STANDALONE, sudo_securid_init, sudo_securid_setup, sudo_securid_verify, NULL, NULL, NULL)
58
58
#endif
59
59
#ifdef HAVE_SIA_SES_INIT
60
 
    AUTH_ENTRY("sia", FLAG_STANDALONE, NULL, sia_setup, sia_verify, sia_cleanup, NULL, NULL)
 
60
    AUTH_ENTRY("sia", FLAG_STANDALONE, NULL, sudo_sia_setup, sudo_sia_verify, sudo_sia_cleanup, NULL, NULL)
61
61
#endif
62
62
#ifdef HAVE_AIXAUTH
63
 
    AUTH_ENTRY("aixauth", FLAG_STANDALONE, NULL, NULL, aixauth_verify, aixauth_cleanup, NULL, NULL)
 
63
    AUTH_ENTRY("aixauth", FLAG_STANDALONE, NULL, NULL, sudo_aix_verify, sudo_aix_cleanup, NULL, NULL)
64
64
#endif
65
65
#ifdef HAVE_FWTK
66
 
    AUTH_ENTRY("fwtk", FLAG_STANDALONE, fwtk_init, NULL, fwtk_verify, fwtk_cleanup, NULL, NULL)
 
66
    AUTH_ENTRY("fwtk", FLAG_STANDALONE, sudo_fwtk_init, NULL, sudo_fwtk_verify, sudo_fwtk_cleanup, NULL, NULL)
67
67
#endif
68
68
#ifdef HAVE_BSD_AUTH_H
69
69
    AUTH_ENTRY("bsdauth", FLAG_STANDALONE, bsdauth_init, NULL, bsdauth_verify, bsdauth_cleanup, NULL, NULL)
71
71
 
72
72
/* Non-standalone entries */
73
73
#ifndef WITHOUT_PASSWD
74
 
    AUTH_ENTRY("passwd", 0, passwd_init, NULL, passwd_verify, passwd_cleanup, NULL, NULL)
 
74
    AUTH_ENTRY("passwd", 0, sudo_passwd_init, NULL, sudo_passwd_verify, sudo_passwd_cleanup, NULL, NULL)
75
75
#endif
76
76
#if defined(HAVE_GETPRPWNAM) && !defined(WITHOUT_PASSWD)
77
 
    AUTH_ENTRY("secureware", 0, secureware_init, NULL, secureware_verify, secureware_cleanup, NULL, NULL)
 
77
    AUTH_ENTRY("secureware", 0, sudo_secureware_init, NULL, sudo_secureware_verify, sudo_secureware_cleanup, NULL, NULL)
78
78
#endif
79
79
#ifdef HAVE_AFS
80
 
    AUTH_ENTRY("afs", 0, NULL, NULL, afs_verify, NULL, NULL, NULL)
 
80
    AUTH_ENTRY("afs", 0, NULL, NULL, sudo_afs_verify, NULL, NULL, NULL)
81
81
#endif
82
82
#ifdef HAVE_DCE
83
 
    AUTH_ENTRY("dce", 0, NULL, NULL, dce_verify, NULL, NULL, NULL)
84
 
#endif
85
 
#ifdef HAVE_KERB4
86
 
    AUTH_ENTRY("kerb4", 0, kerb4_init, NULL, kerb4_verify, NULL, NULL, NULL)
 
83
    AUTH_ENTRY("dce", 0, NULL, NULL, sudo_dce_verify, NULL, NULL, NULL)
87
84
#endif
88
85
#ifdef HAVE_KERB5
89
 
    AUTH_ENTRY("kerb5", 0, kerb5_init, kerb5_setup, kerb5_verify, kerb5_cleanup, NULL, NULL)
 
86
    AUTH_ENTRY("kerb5", 0, sudo_krb5_init, sudo_krb5_setup, sudo_krb5_verify, sudo_krb5_cleanup, NULL, NULL)
90
87
#endif
91
88
#ifdef HAVE_SKEY
92
 
    AUTH_ENTRY("S/Key", 0, NULL, rfc1938_setup, rfc1938_verify, NULL, NULL, NULL)
 
89
    AUTH_ENTRY("S/Key", 0, NULL, sudo_rfc1938_setup, sudo_rfc1938_verify, NULL, NULL, NULL)
93
90
#endif
94
91
#ifdef HAVE_OPIE
95
 
    AUTH_ENTRY("OPIE", 0, NULL, rfc1938_setup, rfc1938_verify, NULL, NULL, NULL)
 
92
    AUTH_ENTRY("OPIE", 0, NULL, sudo_rfc1938_setup, sudo_rfc1938_verify, NULL, NULL, NULL)
96
93
#endif
97
94
    AUTH_ENTRY(NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL)
98
95
};
108
105
{
109
106
    sudo_auth *auth;
110
107
    int status = AUTH_SUCCESS;
 
108
    debug_decl(sudo_auth_init, SUDO_DEBUG_AUTH)
111
109
 
112
110
    if (auth_switch[0].name == NULL)
113
 
        return TRUE;
 
111
        debug_return_int(true);
114
112
 
115
113
    /* Make sure we haven't mixed standalone and shared auth methods. */
116
114
    standalone = IS_STANDALONE(&auth_switch[0]);
117
115
    if (standalone && auth_switch[1].name != NULL) {
118
116
        audit_failure(NewArgv, "invalid authentication methods");
119
 
        log_error(0, _("Invalid authentication methods compiled into sudo!  "
 
117
        log_fatal(0, _("Invalid authentication methods compiled into sudo!  "
120
118
            "You may mix standalone and non-standalone authentication."));
121
 
        return -1;
 
119
        debug_return_int(-1);
122
120
    }
123
121
 
124
122
    /* Set FLAG_ONEANDONLY if there is only one auth method. */
145
143
            }
146
144
        }
147
145
    }
148
 
    return status == AUTH_FATAL ? -1 : TRUE;
 
146
    debug_return_int(status == AUTH_FATAL ? -1 : true);
149
147
}
150
148
 
151
149
int
153
151
{
154
152
    sudo_auth *auth;
155
153
    int status = AUTH_SUCCESS;
 
154
    debug_decl(sudo_auth_cleanup, SUDO_DEBUG_AUTH)
156
155
 
157
156
    /* Call cleanup routines. */
158
157
    for (auth = auth_switch; auth->name; auth++) {
172
171
            }
173
172
        }
174
173
    }
175
 
    return status == AUTH_FATAL ? -1 : TRUE;
 
174
    debug_return_int(status == AUTH_FATAL ? -1 : true);
176
175
}
177
176
 
178
177
int
184
183
    char *p;
185
184
    sudo_auth *auth;
186
185
    sigaction_t sa, osa;
 
186
    debug_decl(verify_user, SUDO_DEBUG_AUTH)
187
187
 
188
188
    /* Enable suspend during password entry. */
189
189
    sigemptyset(&sa.sa_mask);
195
195
    /* XXX - check FLAG_DISABLED too */
196
196
    if (auth_switch[0].name == NULL) {
197
197
        audit_failure(NewArgv, "no authentication methods");
198
 
        log_error(0,
 
198
        log_fatal(0,
199
199
            _("There are no authentication methods compiled into sudo!  "
200
200
            "If you want to turn off authentication, use the "
201
201
            "--disable-authentication configure option."));
202
 
        return -1;
 
202
        debug_return_int(-1);
203
203
    }
204
204
 
205
205
    while (--counter) {
219
219
                else if (status == AUTH_FATAL) {
220
220
                    /* XXX log */
221
221
                    audit_failure(NewArgv, "authentication failure");
222
 
                    return -1;          /* assume error msg already printed */
 
222
                    debug_return_int(-1);/* assume error msg already printed */
223
223
                }
224
224
            }
225
225
        }
259
259
    switch (success) {
260
260
        case AUTH_SUCCESS:
261
261
            (void) sigaction(SIGTSTP, &osa, NULL);
262
 
            rval = TRUE;
 
262
            rval = true;
263
263
            break;
264
264
        case AUTH_INTR:
265
265
        case AUTH_FAILURE:
268
268
                    flags = 0;
269
269
                else
270
270
                    flags = NO_MAIL;
271
 
                log_error(flags, ngettext("%d incorrect password attempt",
 
271
                log_fatal(flags, ngettext("%d incorrect password attempt",
272
272
                    "%d incorrect password attempts",
273
273
                    def_passwd_tries - counter), def_passwd_tries - counter);
274
274
            }
275
275
            audit_failure(NewArgv, "authentication failure");
276
 
            rval = FALSE;
 
276
            rval = false;
277
277
            break;
278
278
        case AUTH_FATAL:
279
279
        default:
282
282
            break;
283
283
    }
284
284
 
285
 
    return rval;
 
285
    debug_return_int(rval);
286
286
}
287
287
 
288
288
int
289
 
sudo_auth_begin_session(struct passwd *pw)
 
289
sudo_auth_begin_session(struct passwd *pw, char **user_env[])
290
290
{
291
291
    sudo_auth *auth;
292
292
    int status;
 
293
    debug_decl(auth_begin_session, SUDO_DEBUG_AUTH)
293
294
 
294
295
    for (auth = auth_switch; auth->name; auth++) {
295
296
        if (auth->begin_session && !IS_DISABLED(auth)) {
296
 
            status = (auth->begin_session)(pw, auth);
 
297
            status = (auth->begin_session)(pw, user_env, auth);
297
298
            if (status == AUTH_FATAL) {
298
299
                /* XXX log */
299
300
                audit_failure(NewArgv, "authentication failure");
300
 
                return -1;              /* assume error msg already printed */
 
301
                debug_return_bool(-1);  /* assume error msg already printed */
301
302
            }
302
303
        }
303
304
    }
304
 
    return TRUE;
 
305
    debug_return_bool(true);
305
306
}
306
307
 
307
308
int
309
310
{
310
311
    sudo_auth *auth;
311
312
    int status;
 
313
    debug_decl(auth_end_session, SUDO_DEBUG_AUTH)
312
314
 
313
315
    for (auth = auth_switch; auth->name; auth++) {
314
316
        if (auth->end_session && !IS_DISABLED(auth)) {
315
317
            status = (auth->end_session)(pw, auth);
316
318
            if (status == AUTH_FATAL) {
317
319
                /* XXX log */
318
 
                return -1;              /* assume error msg already printed */
 
320
                debug_return_bool(-1);  /* assume error msg already printed */
319
321
            }
320
322
        }
321
323
    }
322
 
    return TRUE;
 
324
    debug_return_bool(true);
323
325
}
324
326
 
325
327
static void
326
328
pass_warn(void)
327
329
{
328
330
    const char *warning = def_badpass_message;
 
331
    debug_decl(pass_warn, SUDO_DEBUG_AUTH)
329
332
 
330
333
#ifdef INSULT
331
334
    if (def_insults)
332
335
        warning = INSULT;
333
336
#endif
334
337
    sudo_printf(SUDO_CONV_ERROR_MSG, "%s\n", warning);
 
338
 
 
339
    debug_return;
335
340
}
336
341
 
337
342
char *
339
344
{
340
345
    struct sudo_conv_message msg;
341
346
    struct sudo_conv_reply repl;
 
347
    debug_decl(auth_getpass, SUDO_DEBUG_AUTH)
342
348
 
343
349
    /* Mask user input if pwfeedback set and echo is off. */
344
350
    if (type == SUDO_CONV_PROMPT_ECHO_OFF && def_pwfeedback)
356
362
    memset(&repl, 0, sizeof(repl));
357
363
    sudo_conv(1, &msg, &repl);
358
364
    /* XXX - check for ENOTTY? */
359
 
    return repl.reply;
 
365
    debug_return_str_masked(repl.reply);
360
366
}
361
367
 
362
368
void
363
369
dump_auth_methods(void)
364
370
{
365
371
    sudo_auth *auth;
 
372
    debug_decl(dump_auth_methods, SUDO_DEBUG_AUTH)
366
373
 
367
374
    sudo_printf(SUDO_CONV_INFO_MSG, _("Authentication methods:"));
368
375
    for (auth = auth_switch; auth->name; auth++)
369
376
        sudo_printf(SUDO_CONV_INFO_MSG, " '%s'", auth->name);
370
377
    sudo_printf(SUDO_CONV_INFO_MSG, "\n");
 
378
 
 
379
    debug_return;
371
380
}