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_samsync.h"
30 static void display_group_mem_info(uint32_t rid
,
31 struct netr_DELTA_GROUP_MEMBER
*r
)
34 d_printf("Group mem %u: ", rid
);
35 for (i
=0; i
< r
->num_rids
; i
++) {
36 d_printf("%u ", r
->rids
[i
]);
41 static void display_alias_info(uint32_t rid
,
42 struct netr_DELTA_ALIAS
*r
)
44 d_printf("Alias '%s' ", r
->alias_name
.string
);
45 d_printf("desc='%s' rid=%u\n", r
->description
.string
, r
->rid
);
48 static void display_alias_mem(uint32_t rid
,
49 struct netr_DELTA_ALIAS_MEMBER
*r
)
52 d_printf("Alias rid %u: ", rid
);
53 for (i
=0; i
< r
->sids
.num_sids
; i
++) {
54 d_printf("%s ", sid_string_tos(r
->sids
.sids
[i
].sid
));
59 static void display_account_info(uint32_t rid
,
60 struct netr_DELTA_USER
*r
)
62 fstring hex_nt_passwd
, hex_lm_passwd
;
65 memset(zero_buf
, '\0', sizeof(zero_buf
));
67 /* Decode hashes from password hash (if they are not NULL) */
69 if (memcmp(r
->lmpassword
.hash
, zero_buf
, 16) != 0) {
70 pdb_sethexpwd(hex_lm_passwd
, r
->lmpassword
.hash
, r
->acct_flags
);
72 pdb_sethexpwd(hex_lm_passwd
, NULL
, 0);
75 if (memcmp(r
->ntpassword
.hash
, zero_buf
, 16) != 0) {
76 pdb_sethexpwd(hex_nt_passwd
, r
->ntpassword
.hash
, 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_t *)&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'\n", 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'\n", 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'\n", 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
,
167 struct samsync_context
*ctx
)
169 union netr_DELTA_UNION u
= r
->delta_union
;
170 union netr_DELTA_ID_UNION id
= r
->delta_id_union
;
172 switch (r
->delta_type
) {
173 case NETR_DELTA_DOMAIN
:
174 display_domain_info(u
.domain
);
176 case NETR_DELTA_GROUP
:
177 display_group_info(id
.rid
, u
.group
);
179 case NETR_DELTA_DELETE_GROUP
:
180 display_delete_group(id
.rid
);
182 case NETR_DELTA_RENAME_GROUP
:
183 display_rename_group(id
.rid
, u
.rename_group
);
185 case NETR_DELTA_USER
:
186 display_account_info(id
.rid
, u
.user
);
188 case NETR_DELTA_DELETE_USER
:
189 display_delete_user(id
.rid
);
191 case NETR_DELTA_RENAME_USER
:
192 display_rename_user(id
.rid
, u
.rename_user
);
194 case NETR_DELTA_GROUP_MEMBER
:
195 display_group_mem_info(id
.rid
, u
.group_member
);
197 case NETR_DELTA_ALIAS
:
198 display_alias_info(id
.rid
, u
.alias
);
200 case NETR_DELTA_DELETE_ALIAS
:
201 display_delete_alias(id
.rid
);
203 case NETR_DELTA_RENAME_ALIAS
:
204 display_rename_alias(id
.rid
, u
.rename_alias
);
206 case NETR_DELTA_ALIAS_MEMBER
:
207 display_alias_mem(id
.rid
, u
.alias_member
);
209 case NETR_DELTA_POLICY
:
210 printf("Policy: %s\n",
211 sid_string_dbg(id
.sid
));
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: %s\n",
219 sid_string_dbg(id
.sid
));
221 case NETR_DELTA_ACCOUNT
:
222 printf("Account: %s\n",
223 sid_string_dbg(id
.sid
));
225 case NETR_DELTA_DELETE_ACCOUNT
:
226 printf("Delete Account: %s\n",
227 sid_string_dbg(id
.sid
));
229 case NETR_DELTA_SECRET
:
230 printf("Secret: %s\n",
233 case NETR_DELTA_DELETE_SECRET
:
234 printf("Delete Secret: %s\n",
237 case NETR_DELTA_DELETE_GROUP2
:
238 printf("Delete Group2: %s\n",
239 u
.delete_group
->account_name
);
241 case NETR_DELTA_DELETE_USER2
:
242 printf("Delete User2: %s\n",
243 u
.delete_user
->account_name
);
245 case NETR_DELTA_MODIFY_COUNT
:
246 printf("sam sequence update: 0x%016llx\n",
247 (unsigned long long) *u
.modified_count
);
250 /* The following types are recognised but not handled */
251 case NETR_DELTA_POLICY
:
252 d_printf("NETR_DELTA_POLICY not handled\n");
254 case NETR_DELTA_TRUSTED_DOMAIN
:
255 d_printf("NETR_DELTA_TRUSTED_DOMAIN not handled\n");
257 case NETR_DELTA_ACCOUNT
:
258 d_printf("NETR_DELTA_ACCOUNT not handled\n");
260 case NETR_DELTA_SECRET
:
261 d_printf("NETR_DELTA_SECRET not handled\n");
263 case NETR_DELTA_MODIFY_COUNT
:
264 d_printf("NETR_DELTA_MODIFY_COUNT not handled\n");
266 case NETR_DELTA_DELETE_TRUST
:
267 d_printf("NETR_DELTA_DELETE_TRUST not handled\n");
269 case NETR_DELTA_DELETE_ACCOUNT
:
270 d_printf("NETR_DELTA_DELETE_ACCOUNT not handled\n");
272 case NETR_DELTA_DELETE_SECRET
:
273 d_printf("NETR_DELTA_DELETE_SECRET not handled\n");
275 case NETR_DELTA_DELETE_GROUP2
:
276 d_printf("NETR_DELTA_DELETE_GROUP2 not handled\n");
278 case NETR_DELTA_DELETE_USER2
:
279 d_printf("NETR_DELTA_DELETE_USER2 not handled\n");
283 printf("unknown delta type 0x%02x\n",
291 static NTSTATUS
display_sam_entries(TALLOC_CTX
*mem_ctx
,
292 enum netr_SamDatabaseID database_id
,
293 struct netr_DELTA_ENUM_ARRAY
*r
,
294 uint64_t *sequence_num
,
295 struct samsync_context
*ctx
)
299 for (i
= 0; i
< r
->num_deltas
; i
++) {
300 display_sam_entry(mem_ctx
, database_id
, &r
->delta_enum
[i
],
307 const struct samsync_ops libnet_samsync_display_ops
= {
308 .process_objects
= display_sam_entries
,