~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source3/auth/user_info.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Unix SMB/CIFS implementation.
 
3
   Authentication utility functions
 
4
   Copyright (C) Volker Lendecke 2010
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 3 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
#include "includes.h"
 
21
#include "auth.h"
 
22
#include "librpc/gen_ndr/samr.h"
 
23
 
 
24
#undef DBGC_CLASS
 
25
#define DBGC_CLASS DBGC_AUTH
 
26
 
 
27
static int clear_samr_Password(struct samr_Password *password)
 
28
{
 
29
        memset(password->hash, '\0', sizeof(password->hash));
 
30
        return 0;
 
31
}
 
32
 
 
33
static int clear_string(char *password)
 
34
{
 
35
        memset(password, '\0', strlen(password));
 
36
        return 0;
 
37
}
 
38
 
 
39
/****************************************************************************
 
40
 Create an auth_usersupplied_data structure
 
41
****************************************************************************/
 
42
 
 
43
NTSTATUS make_user_info(struct auth_usersupplied_info **ret_user_info,
 
44
                        const char *smb_name,
 
45
                        const char *internal_username,
 
46
                        const char *client_domain,
 
47
                        const char *domain,
 
48
                        const char *workstation_name,
 
49
                        const DATA_BLOB *lm_pwd,
 
50
                        const DATA_BLOB *nt_pwd,
 
51
                        const struct samr_Password *lm_interactive_pwd,
 
52
                        const struct samr_Password *nt_interactive_pwd,
 
53
                        const char *plaintext_password,
 
54
                        enum auth_password_state password_state)
 
55
{
 
56
        struct auth_usersupplied_info *user_info;
 
57
        *ret_user_info = NULL;
 
58
 
 
59
        DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username, smb_name));
 
60
 
 
61
        /* FIXME: Have the caller provide a talloc context of the
 
62
         * correct lifetime (possibly talloc_tos(), but it depends on
 
63
         * the caller) */
 
64
        user_info = talloc_zero(NULL, struct auth_usersupplied_info);
 
65
        if (user_info == NULL) {
 
66
                DEBUG(0,("talloc failed for user_info\n"));
 
67
                return NT_STATUS_NO_MEMORY;
 
68
        }
 
69
 
 
70
        DEBUG(5,("making strings for %s's user_info struct\n", internal_username));
 
71
 
 
72
        user_info->client.account_name = talloc_strdup(user_info, smb_name);
 
73
        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->client.account_name, user_info);
 
74
 
 
75
        user_info->mapped.account_name = talloc_strdup(user_info, internal_username);
 
76
        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->mapped.account_name, user_info);
 
77
 
 
78
        user_info->mapped.domain_name = talloc_strdup(user_info, domain);
 
79
        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->mapped.domain_name, user_info);
 
80
 
 
81
        user_info->client.domain_name = talloc_strdup(user_info, client_domain);
 
82
        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->client.domain_name, user_info);
 
83
 
 
84
        user_info->workstation_name = talloc_strdup(user_info, workstation_name);
 
85
        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->workstation_name, user_info);
 
86
 
 
87
        DEBUG(5,("making blobs for %s's user_info struct\n", internal_username));
 
88
 
 
89
        if (lm_pwd && lm_pwd->data) {
 
90
                user_info->password.response.lanman = data_blob_talloc(user_info, lm_pwd->data, lm_pwd->length);
 
91
                NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.response.lanman.data, user_info);
 
92
        }
 
93
        if (nt_pwd && nt_pwd->data) {
 
94
                user_info->password.response.nt = data_blob_talloc(user_info, nt_pwd->data, nt_pwd->length);
 
95
                NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.response.nt.data, user_info);
 
96
        }
 
97
        if (lm_interactive_pwd) {
 
98
                user_info->password.hash.lanman = talloc(user_info, struct samr_Password);
 
99
                NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.hash.lanman, user_info);
 
100
                memcpy(user_info->password.hash.lanman->hash, lm_interactive_pwd->hash,
 
101
                       sizeof(user_info->password.hash.lanman->hash));
 
102
                talloc_set_destructor(user_info->password.hash.lanman, clear_samr_Password);
 
103
        }
 
104
 
 
105
        if (nt_interactive_pwd) {
 
106
                user_info->password.hash.nt = talloc(user_info, struct samr_Password);
 
107
                NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.hash.nt, user_info);
 
108
                memcpy(user_info->password.hash.nt->hash, nt_interactive_pwd->hash,
 
109
                       sizeof(user_info->password.hash.nt->hash));
 
110
                talloc_set_destructor(user_info->password.hash.nt, clear_samr_Password);
 
111
        }
 
112
 
 
113
        if (plaintext_password) {
 
114
                user_info->password.plaintext = talloc_strdup(user_info, plaintext_password);
 
115
                NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.plaintext, user_info);
 
116
                talloc_set_destructor(user_info->password.plaintext, clear_string);
 
117
        }
 
118
 
 
119
        user_info->password_state = password_state;
 
120
 
 
121
        user_info->logon_parameters = 0;
 
122
 
 
123
        DEBUG(10,("made a user_info for %s (%s)\n", internal_username, smb_name));
 
124
        *ret_user_info = user_info;
 
125
        return NT_STATUS_OK;
 
126
}
 
127
 
 
128
/***************************************************************************
 
129
 Free a user_info struct
 
130
***************************************************************************/
 
131
 
 
132
void free_user_info(struct auth_usersupplied_info **user_info)
 
133
{
 
134
        TALLOC_FREE(*user_info);
 
135
}