Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/auth/pass_check.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Password checking
    44   Copyright (C) Andrew Tridgell 1992-1998
    5    
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2222
    2323#include "includes.h"
     24#include "system/passwd.h"
     25#include "auth.h"
    2426
    2527#undef DBGC_CLASS
    2628#define DBGC_CLASS DBGC_AUTH
     29
     30/* what is the longest significant password available on your system?
     31 Knowing this speeds up password searches a lot */
     32#ifndef PASSWORD_LENGTH
     33#define PASSWORD_LENGTH 8
     34#endif
    2735
    2836/* these are kept here to keep the string_combinations function simple */
     
    493501it assumes the string starts lowercased
    494502****************************************************************************/
    495 static NTSTATUS string_combinations2(char *s, int offset, NTSTATUS (*fn) (const char *),
    496                                  int N)
     503static NTSTATUS string_combinations2(char *s, int offset,
     504                                     NTSTATUS (*fn)(const char *s,
     505                                                    void *private_data),
     506                                     int N, void *private_data)
    497507{
    498508        int len = strlen(s);
     
    505515
    506516        if (N <= 0 || offset >= len)
    507                 return (fn(s));
     517                return (fn(s, private_data));
    508518
    509519        for (i = offset; i < (len - (N - 1)); i++) {
    510520                char c = s[i];
    511                 if (!islower_ascii(c))
     521                if (!islower_m(c))
    512522                        continue;
    513                 s[i] = toupper_ascii(c);
    514                 if (!NT_STATUS_EQUAL(nt_status = string_combinations2(s, i + 1, fn, N - 1),NT_STATUS_WRONG_PASSWORD)) {
    515                         return (nt_status);
     523                s[i] = toupper_m(c);
     524                nt_status = string_combinations2(s, i + 1, fn, N - 1,
     525                                                 private_data);
     526                if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
     527                        return nt_status;
    516528                }
    517529                s[i] = c;
     
    527539it assumes the string starts lowercased
    528540****************************************************************************/
    529 static NTSTATUS string_combinations(char *s, NTSTATUS (*fn) (const char *), int N)
     541static NTSTATUS string_combinations(char *s,
     542                                    NTSTATUS (*fn)(const char *s,
     543                                                   void *private_data),
     544                                    int N, void *private_data)
    530545{
    531546        int n;
    532547        NTSTATUS nt_status;
    533         for (n = 1; n <= N; n++)
    534                 if (!NT_STATUS_EQUAL(nt_status = string_combinations2(s, 0, fn, n), NT_STATUS_WRONG_PASSWORD))
     548        for (n = 1; n <= N; n++) {
     549                nt_status = string_combinations2(s, 0, fn, n, private_data);
     550                if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
    535551                        return nt_status;
     552                }
     553        }
    536554        return NT_STATUS_WRONG_PASSWORD;
    537555}
     
    541559core of password checking routine
    542560****************************************************************************/
    543 static NTSTATUS password_check(const char *password)
     561static NTSTATUS password_check(const char *password, void *private_data)
    544562{
    545563#ifdef WITH_PAM
    546         return smb_pam_passcheck(get_this_user(), password);
     564        const char *rhost = (const char *)private_data;
     565        return smb_pam_passcheck(get_this_user(), rhost, password);
    547566#else
    548567
     
    560579
    561580#ifdef OSF1_ENH_SEC
    562        
     581
    563582        ret = (strcmp(osf1_bigcrypt(password, get_this_salt()),
    564583                      get_this_crypted()) == 0);
     
    573592                return NT_STATUS_WRONG_PASSWORD;
    574593        }
    575        
     594
    576595#endif /* OSF1_ENH_SEC */
    577        
     596
    578597#ifdef ULTRIX_AUTH
    579598        ret = (strcmp((char *)crypt16(password, get_this_salt()), get_this_crypted()) == 0);
     
    583602                return NT_STATUS_WRONG_PASSWORD;
    584603        }
    585        
     604
    586605#endif /* ULTRIX_AUTH */
    587        
     606
    588607#ifdef LINUX_BIGCRYPT
    589608        ret = (linux_bigcrypt(password, get_this_salt(), get_this_crypted()));
     
    594613        }
    595614#endif /* LINUX_BIGCRYPT */
    596        
     615
    597616#if defined(HAVE_BIGCRYPT) && defined(HAVE_CRYPT) && defined(USE_BOTH_CRYPT_CALLS)
    598        
     617
    599618        /*
    600619         * Some systems have bigcrypt in the C library but might not
     
    614633        }
    615634#else /* HAVE_BIGCRYPT && HAVE_CRYPT && USE_BOTH_CRYPT_CALLS */
    616        
     635
    617636#ifdef HAVE_BIGCRYPT
    618637        ret = (strcmp(bigcrypt(password, get_this_salt()), get_this_crypted()) == 0);
     
    623642        }
    624643#endif /* HAVE_BIGCRYPT */
    625        
     644
    626645#ifndef HAVE_CRYPT
    627646        DEBUG(1, ("Warning - no crypt available\n"));
     
    648667****************************************************************************/
    649668
    650 NTSTATUS pass_check(const struct passwd *pass, const char *user, const char *password,
    651                     int pwlen, bool (*fn) (const char *, const char *), bool run_cracker)
     669NTSTATUS pass_check(const struct passwd *pass,
     670                    const char *user,
     671                    const char *rhost,
     672                    const char *password,
     673                    bool run_cracker)
    652674{
    653675        char *pass2 = NULL;
     
    663685                return NT_STATUS_LOGON_FAILURE;
    664686
    665         if (((!*password) || (!pwlen)) && !lp_null_passwords())
     687        if ((!*password) && !lp_null_passwords())
    666688                return NT_STATUS_LOGON_FAILURE;
    667689
     
    677699        }
    678700
    679         DEBUG(4, ("pass_check: Checking (PAM) password for user %s (l=%d)\n", user, pwlen));
     701        DEBUG(4, ("pass_check: Checking (PAM) password for user %s\n", user));
    680702
    681703#else /* Not using PAM */
    682704
    683         DEBUG(4, ("pass_check: Checking password for user %s (l=%d)\n", user, pwlen));
     705        DEBUG(4, ("pass_check: Checking password for user %s\n", user));
    684706
    685707        if (!pass) {
     
    819841
    820842        /* try it as it came to us */
    821         nt_status = password_check(password);
     843        nt_status = password_check(password, (void *)rhost);
    822844        if NT_STATUS_IS_OK(nt_status) {
    823                 if (fn) {
    824                         fn(user, password);
    825                 }
    826845                return (nt_status);
    827846        } else if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
     
    850869        if (strhasupper(pass2)) {
    851870                strlower_m(pass2);
    852                 if NT_STATUS_IS_OK(nt_status = password_check(pass2)) {
    853                         if (fn)
    854                                 fn(user, pass2);
     871                nt_status = password_check(pass2, (void *)rhost);
     872                if (NT_STATUS_IS_OK(nt_status)) {
    855873                        return (nt_status);
    856874                }
     
    864882        /* last chance - all combinations of up to level chars upper! */
    865883        strlower_m(pass2);
    866  
    867         if (NT_STATUS_IS_OK(nt_status = string_combinations(pass2, password_check, level))) {
    868                 if (fn)
    869                         fn(user, pass2);
     884
     885        nt_status = string_combinations(pass2, password_check, level,
     886                                        (void *)rhost);
     887        if (NT_STATUS_IS_OK(nt_status)) {
    870888                return nt_status;
    871889        }
    872        
     890
    873891        return NT_STATUS_WRONG_PASSWORD;
    874892}
Note: See TracChangeset for help on using the changeset viewer.