2 Unix SMB/CIFS implementation.
3 dump the remote SAM using rpc samsync operations
5 Copyright (C) Andrew Tridgell 2002
6 Copyright (C) Tim Potter 2001,2002
7 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2005
8 Modified by Volker Lendecke 2002
9 Copyright (C) Jeremy Allison 2005.
10 Copyright (C) Guenther Deschner 2008.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "libnet/libnet.h"
29 static void display_group_mem_info(uint32_t rid
,
30 struct netr_DELTA_GROUP_MEMBER
*r
)
33 d_printf("Group mem %u: ", rid
);
34 for (i
=0; i
< r
->num_rids
; i
++) {
35 d_printf("%u ", r
->rids
[i
]);
40 static void display_alias_info(uint32_t rid
,
41 struct netr_DELTA_ALIAS
*r
)
43 d_printf("Alias '%s' ", r
->alias_name
.string
);
44 d_printf("desc='%s' rid=%u\n", r
->description
.string
, r
->rid
);
47 static void display_alias_mem(uint32_t rid
,
48 struct netr_DELTA_ALIAS_MEMBER
*r
)
51 d_printf("Alias rid %u: ", rid
);
52 for (i
=0; i
< r
->sids
.num_sids
; i
++) {
53 d_printf("%s ", sid_string_tos(r
->sids
.sids
[i
].sid
));
58 static void display_account_info(uint32_t rid
,
59 struct netr_DELTA_USER
*r
)
61 fstring hex_nt_passwd
, hex_lm_passwd
;
62 uchar lm_passwd
[16], nt_passwd
[16];
63 static uchar zero_buf
[16];
65 /* Decode hashes from password hash (if they are not NULL) */
67 if (memcmp(r
->lmpassword
.hash
, zero_buf
, 16) != 0) {
68 sam_pwd_hash(r
->rid
, r
->lmpassword
.hash
, lm_passwd
, 0);
69 pdb_sethexpwd(hex_lm_passwd
, lm_passwd
, r
->acct_flags
);
71 pdb_sethexpwd(hex_lm_passwd
, NULL
, 0);
74 if (memcmp(r
->ntpassword
.hash
, zero_buf
, 16) != 0) {
75 sam_pwd_hash(r
->rid
, r
->ntpassword
.hash
, nt_passwd
, 0);
76 pdb_sethexpwd(hex_nt_passwd
, nt_passwd
, r
->acct_flags
);
78 pdb_sethexpwd(hex_nt_passwd
, NULL
, 0);
81 printf("%s:%d:%s:%s:%s:LCT-0\n",
82 r
->account_name
.string
,
83 r
->rid
, hex_lm_passwd
, hex_nt_passwd
,
84 pdb_encode_acct_ctrl(r
->acct_flags
, NEW_PW_FORMAT_SPACE_PADDED_LEN
));
87 static void display_domain_info(struct netr_DELTA_DOMAIN
*r
)
90 struct netr_AcctLockStr
*lockstr
= NULL
;
92 TALLOC_CTX
*mem_ctx
= talloc_tos();
94 status
= pull_netr_AcctLockStr(mem_ctx
, &r
->account_lockout
,
96 if (!NT_STATUS_IS_OK(status
)) {
97 d_printf("failed to pull account lockout string: %s\n",
101 u_logout
= uint64s_nt_time_to_unix_abs((const uint64
*)&r
->force_logoff_time
);
103 d_printf("Domain name: %s\n", r
->domain_name
.string
);
105 d_printf("Minimal Password Length: %d\n", r
->min_password_length
);
106 d_printf("Password History Length: %d\n", r
->password_history_length
);
108 d_printf("Force Logoff: %d\n", (int)u_logout
);
110 d_printf("Max Password Age: %s\n", display_time(r
->max_password_age
));
111 d_printf("Min Password Age: %s\n", display_time(r
->min_password_age
));
114 d_printf("Lockout Time: %s\n", display_time((NTTIME
)lockstr
->lockout_duration
));
115 d_printf("Lockout Reset Time: %s\n", display_time((NTTIME
)lockstr
->reset_count
));
116 d_printf("Bad Attempt Lockout: %d\n", lockstr
->bad_attempt_lockout
);
119 d_printf("User must logon to change password: %d\n", r
->logon_to_chgpass
);
122 static void display_group_info(uint32_t rid
, struct netr_DELTA_GROUP
*r
)
124 d_printf("Group '%s' ", r
->group_name
.string
);
125 d_printf("desc='%s', rid=%u\n", r
->description
.string
, rid
);
128 static void display_delete_group(uint32_t rid
)
130 d_printf("Delete Group '%d' ", rid
);
133 static void display_rename_group(uint32_t rid
, struct netr_DELTA_RENAME
*r
)
135 d_printf("Rename Group '%d' ", rid
);
136 d_printf("Rename Group: %s -> %s\n",
137 r
->OldName
.string
, r
->NewName
.string
);
140 static void display_delete_user(uint32_t rid
)
142 d_printf("Delete User '%d' ", rid
);
145 static void display_rename_user(uint32_t rid
, struct netr_DELTA_RENAME
*r
)
147 d_printf("Rename User '%d' ", rid
);
148 d_printf("Rename User: %s -> %s\n",
149 r
->OldName
.string
, r
->NewName
.string
);
152 static void display_delete_alias(uint32_t rid
)
154 d_printf("Delete Alias '%d' ", rid
);
157 static void display_rename_alias(uint32_t rid
, struct netr_DELTA_RENAME
*r
)
159 d_printf("Rename Alias '%d' ", rid
);
160 d_printf("Rename Alias: %s -> %s\n",
161 r
->OldName
.string
, r
->NewName
.string
);
164 static NTSTATUS
display_sam_entry(TALLOC_CTX
*mem_ctx
,
165 enum netr_SamDatabaseID database_id
,
166 struct netr_DELTA_ENUM
*r
,
168 struct samsync_context
*ctx
)
170 union netr_DELTA_UNION u
= r
->delta_union
;
171 union netr_DELTA_ID_UNION id
= r
->delta_id_union
;
173 switch (r
->delta_type
) {
174 case NETR_DELTA_DOMAIN
:
175 display_domain_info(u
.domain
);
177 case NETR_DELTA_GROUP
:
178 display_group_info(id
.rid
, u
.group
);
180 case NETR_DELTA_DELETE_GROUP
:
181 display_delete_group(id
.rid
);
183 case NETR_DELTA_RENAME_GROUP
:
184 display_rename_group(id
.rid
, u
.rename_group
);
186 case NETR_DELTA_USER
:
187 display_account_info(id
.rid
, u
.user
);
189 case NETR_DELTA_DELETE_USER
:
190 display_delete_user(id
.rid
);
192 case NETR_DELTA_RENAME_USER
:
193 display_rename_user(id
.rid
, u
.rename_user
);
195 case NETR_DELTA_GROUP_MEMBER
:
196 display_group_mem_info(id
.rid
, u
.group_member
);
198 case NETR_DELTA_ALIAS
:
199 display_alias_info(id
.rid
, u
.alias
);
201 case NETR_DELTA_DELETE_ALIAS
:
202 display_delete_alias(id
.rid
);
204 case NETR_DELTA_RENAME_ALIAS
:
205 display_rename_alias(id
.rid
, u
.rename_alias
);
207 case NETR_DELTA_ALIAS_MEMBER
:
208 display_alias_mem(id
.rid
, u
.alias_member
);
210 case NETR_DELTA_POLICY
:
213 case NETR_DELTA_TRUSTED_DOMAIN
:
214 printf("Trusted Domain: %s\n",
215 u
.trusted_domain
->domain_name
.string
);
217 case NETR_DELTA_DELETE_TRUST
:
218 printf("Delete Trust: %d\n",
219 u
.delete_trust
.unknown
);
221 case NETR_DELTA_ACCOUNT
:
224 case NETR_DELTA_DELETE_ACCOUNT
:
225 printf("Delete Account: %d\n",
226 u
.delete_account
.unknown
);
228 case NETR_DELTA_SECRET
:
231 case NETR_DELTA_DELETE_SECRET
:
232 printf("Delete Secret: %d\n",
233 u
.delete_secret
.unknown
);
235 case NETR_DELTA_DELETE_GROUP2
:
236 printf("Delete Group2: %s\n",
237 u
.delete_group
->account_name
);
239 case NETR_DELTA_DELETE_USER2
:
240 printf("Delete User2: %s\n",
241 u
.delete_user
->account_name
);
243 case NETR_DELTA_MODIFY_COUNT
:
244 printf("sam sequence update: 0x%016llx\n",
245 (unsigned long long) *u
.modified_count
);
248 /* The following types are recognised but not handled */
249 case NETR_DELTA_POLICY
:
250 d_printf("NETR_DELTA_POLICY not handled\n");
252 case NETR_DELTA_TRUSTED_DOMAIN
:
253 d_printf("NETR_DELTA_TRUSTED_DOMAIN not handled\n");
255 case NETR_DELTA_ACCOUNT
:
256 d_printf("NETR_DELTA_ACCOUNT not handled\n");
258 case NETR_DELTA_SECRET
:
259 d_printf("NETR_DELTA_SECRET not handled\n");
261 case NETR_DELTA_MODIFY_COUNT
:
262 d_printf("NETR_DELTA_MODIFY_COUNT not handled\n");
264 case NETR_DELTA_DELETE_TRUST
:
265 d_printf("NETR_DELTA_DELETE_TRUST not handled\n");
267 case NETR_DELTA_DELETE_ACCOUNT
:
268 d_printf("NETR_DELTA_DELETE_ACCOUNT not handled\n");
270 case NETR_DELTA_DELETE_SECRET
:
271 d_printf("NETR_DELTA_DELETE_SECRET not handled\n");
273 case NETR_DELTA_DELETE_GROUP2
:
274 d_printf("NETR_DELTA_DELETE_GROUP2 not handled\n");
276 case NETR_DELTA_DELETE_USER2
:
277 d_printf("NETR_DELTA_DELETE_USER2 not handled\n");
281 printf("unknown delta type 0x%02x\n",
289 NTSTATUS
display_sam_entries(TALLOC_CTX
*mem_ctx
,
290 enum netr_SamDatabaseID database_id
,
291 struct netr_DELTA_ENUM_ARRAY
*r
,
293 struct samsync_context
*ctx
)
297 for (i
= 0; i
< r
->num_deltas
; i
++) {
298 display_sam_entry(mem_ctx
, database_id
, &r
->delta_enum
[i
],