summaryrefslogtreecommitdiff
path: root/source3/passdb/sampass.c
blob: 967e0502e38bc8b682a813624e86070235ff9f33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 675
 * Mass Ave, Cambridge, MA 02139, USA.
 */

#include "includes.h"

#ifdef USE_SMBPASS_DB

extern int DEBUGLEVEL;
extern pstring samlogon_user;
extern BOOL sam_logon_in_ssb;

extern DOM_SID global_sam_sid;

/***************************************************************
 Start to enumerate the smbpasswd list. Returns a void pointer
 to ensure no modification outside this module.
****************************************************************/

void *startsamfilepwent(BOOL update)
{
	return startsmbpwent(update);
}

/***************************************************************
 End enumeration of the smbpasswd list.
****************************************************************/

void endsamfilepwent(void *vp)
{
	endsmbpwent(vp);
}

/*************************************************************************
 Return the current position in the smbpasswd list as an SMB_BIG_UINT.
 This must be treated as an opaque token.
*************************************************************************/

SMB_BIG_UINT getsamfilepwpos(void *vp)
{
	return getsmbpwpos(vp);
}

/*************************************************************************
 Set the current position in the smbpasswd list from an SMB_BIG_UINT.
 This must be treated as an opaque token.
*************************************************************************/

BOOL setsamfilepwpos(void *vp, SMB_BIG_UINT tok)
{
	return setsmbpwpos(vp, tok);
}

/*************************************************************************
 Routine to return the next entry in the smbpasswd list.
 this function is a nice, messy combination of reading:
 - the smbpasswd file
 - the unix password database
 - smb.conf options (not done at present).
 *************************************************************************/

static struct sam_passwd *getsamfile21pwent(void *vp)
{
	struct sam_passwd *user;

	static pstring full_name;
	static pstring home_dir;
	static pstring home_drive;
	static pstring logon_script;
	static pstring profile_path;
	static pstring acct_desc;
	static pstring workstations;

	DEBUG(5,("getsamfile21pwent\n"));

	user = pwdb_smb_to_sam(getsmbpwent(vp));
	if (user == NULL)
	{
		return NULL;
	}

	/*
	 * get all the other gubbins we need
	 */

	pstrcpy(samlogon_user, user->nt_name);

	if (samlogon_user[strlen(samlogon_user)-1] == '$' && 
	    user->group_rid != DOMAIN_GROUP_RID_USERS)
	{
		DEBUG(0,("trust account %s should be in DOMAIN_GROUP_RID_USERS\n",
		          samlogon_user));
	}

	/* XXXX hack to get standard_sub_basic() to use sam logon username */
	/* possibly a better way would be to do a become_user() call */
	sam_logon_in_ssb = True;

	pstrcpy(full_name    , "");
	pstrcpy(logon_script , lp_logon_script       ());
	pstrcpy(profile_path , lp_logon_path         ());
	pstrcpy(home_drive   , lp_logon_drive        ());
	pstrcpy(home_dir     , lp_logon_home         ());
	pstrcpy(acct_desc    , "");
	pstrcpy(workstations , "");

	sam_logon_in_ssb = False;

	user->full_name    = full_name;
	user->home_dir     = home_dir;
	user->dir_drive    = home_drive;
	user->logon_script = logon_script;
	user->profile_path = profile_path;
	user->acct_desc    = acct_desc;
	user->workstations = workstations;

	user->unknown_str = NULL; /* don't know, yet! */
	user->munged_dial = NULL; /* "munged" dial-back telephone number */

	user->unknown_3 = 0xffffff; /* don't know */
	user->logon_divs = 168; /* hours per week */
	user->hours_len = 21; /* 21 times 8 bits = 168 */
	memset(user->hours, 0xff, user->hours_len); /* available at all hours */
	user->unknown_5 = 0x00020000; /* don't know */
	user->unknown_6 = 0x000004ec; /* don't know */

	return user;
}

/*
 * Stub functions - implemented in terms of others.
 */

static BOOL mod_samfile21pwd_entry(struct sam_passwd* pwd, BOOL override)
{
 	return mod_smbpwd_entry(pwdb_sam_to_smb(pwd), override);
}

static BOOL add_samfile21pwd_entry(struct sam_passwd *newpwd)
{
 	return add_smbpwd_entry(pwdb_sam_to_smb(newpwd));
}

static struct sam_disp_info *getsamfiledispntnam(const char *name)
{
	return pwdb_sam_to_dispinfo(getsam21pwntnam(name));
}

static struct sam_disp_info *getsamfiledisprid(uint32 rid)
{
	return pwdb_sam_to_dispinfo(getsam21pwrid(rid));
}

static struct sam_disp_info *getsamfiledispent(void *vp)
{
	return pwdb_sam_to_dispinfo(getsam21pwent(vp));
}

static struct sam_passdb_ops file_ops = {
  startsamfilepwent,
  endsamfilepwent,
  getsamfilepwpos,
  setsamfilepwpos,
  iterate_getsam21pwntnam,
  iterate_getsam21pwuid,
  iterate_getsam21pwrid, 
  getsamfile21pwent,
  add_samfile21pwd_entry,
  mod_samfile21pwd_entry,
  getsamfiledispntnam,
  getsamfiledisprid,
  getsamfiledispent
};

struct sam_passdb_ops *file_initialise_sam_password_db(void)
{    
  return &file_ops;
}

#else
 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
 void sampass_dummy_function(void) { } /* stop some compilers complaining */
#endif /* USE_SMBPASS_DB */