smbd: Convert recursive_rmdir to synthetic_smb_fname
[Samba/bjacke.git] / source3 / libnet / libnet_samsync_display.c
blobd503ffb4283e30e4458288025e917f26cbf2a5f8
1 /*
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/>.
26 #include "includes.h"
27 #include "libnet/libnet_samsync.h"
28 #include "passdb.h"
30 static void display_group_mem_info(uint32_t rid,
31 struct netr_DELTA_GROUP_MEMBER *r)
33 int i;
34 d_printf("Group mem %u: ", rid);
35 for (i=0; i< r->num_rids; i++) {
36 d_printf("%u ", r->rids[i]);
38 d_printf("\n");
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)
51 int i;
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));
56 d_printf("\n");
59 static void display_account_info(uint32_t rid,
60 struct netr_DELTA_USER *r)
62 fstring hex_nt_passwd, hex_lm_passwd;
63 uchar zero_buf[16];
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);
71 } else {
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);
77 } else {
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)
89 time_t u_logout;
90 struct netr_AcctLockStr *lockstr = NULL;
91 NTSTATUS status;
92 TALLOC_CTX *mem_ctx = talloc_tos();
94 status = pull_netr_AcctLockStr(mem_ctx, &r->account_lockout,
95 &lockstr);
96 if (!NT_STATUS_IS_OK(status)) {
97 d_printf("failed to pull account lockout string: %s\n",
98 nt_errstr(status));
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));
113 if (lockstr) {
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);
175 break;
176 case NETR_DELTA_GROUP:
177 display_group_info(id.rid, u.group);
178 break;
179 case NETR_DELTA_DELETE_GROUP:
180 display_delete_group(id.rid);
181 break;
182 case NETR_DELTA_RENAME_GROUP:
183 display_rename_group(id.rid, u.rename_group);
184 break;
185 case NETR_DELTA_USER:
186 display_account_info(id.rid, u.user);
187 break;
188 case NETR_DELTA_DELETE_USER:
189 display_delete_user(id.rid);
190 break;
191 case NETR_DELTA_RENAME_USER:
192 display_rename_user(id.rid, u.rename_user);
193 break;
194 case NETR_DELTA_GROUP_MEMBER:
195 display_group_mem_info(id.rid, u.group_member);
196 break;
197 case NETR_DELTA_ALIAS:
198 display_alias_info(id.rid, u.alias);
199 break;
200 case NETR_DELTA_DELETE_ALIAS:
201 display_delete_alias(id.rid);
202 break;
203 case NETR_DELTA_RENAME_ALIAS:
204 display_rename_alias(id.rid, u.rename_alias);
205 break;
206 case NETR_DELTA_ALIAS_MEMBER:
207 display_alias_mem(id.rid, u.alias_member);
208 break;
209 case NETR_DELTA_POLICY:
210 printf("Policy: %s\n",
211 sid_string_dbg(id.sid));
212 break;
213 case NETR_DELTA_TRUSTED_DOMAIN:
214 printf("Trusted Domain: %s\n",
215 u.trusted_domain->domain_name.string);
216 break;
217 case NETR_DELTA_DELETE_TRUST:
218 printf("Delete Trust: %s\n",
219 sid_string_dbg(id.sid));
220 break;
221 case NETR_DELTA_ACCOUNT:
222 printf("Account: %s\n",
223 sid_string_dbg(id.sid));
224 break;
225 case NETR_DELTA_DELETE_ACCOUNT:
226 printf("Delete Account: %s\n",
227 sid_string_dbg(id.sid));
228 break;
229 case NETR_DELTA_SECRET:
230 printf("Secret: %s\n",
231 id.name);
232 break;
233 case NETR_DELTA_DELETE_SECRET:
234 printf("Delete Secret: %s\n",
235 id.name);
236 break;
237 case NETR_DELTA_DELETE_GROUP2:
238 printf("Delete Group2: %s\n",
239 u.delete_group->account_name);
240 break;
241 case NETR_DELTA_DELETE_USER2:
242 printf("Delete User2: %s\n",
243 u.delete_user->account_name);
244 break;
245 case NETR_DELTA_MODIFY_COUNT:
246 printf("sam sequence update: 0x%016llx\n",
247 (unsigned long long) *u.modified_count);
248 break;
249 #if 0
250 /* The following types are recognised but not handled */
251 case NETR_DELTA_POLICY:
252 d_printf("NETR_DELTA_POLICY not handled\n");
253 break;
254 case NETR_DELTA_TRUSTED_DOMAIN:
255 d_printf("NETR_DELTA_TRUSTED_DOMAIN not handled\n");
256 break;
257 case NETR_DELTA_ACCOUNT:
258 d_printf("NETR_DELTA_ACCOUNT not handled\n");
259 break;
260 case NETR_DELTA_SECRET:
261 d_printf("NETR_DELTA_SECRET not handled\n");
262 break;
263 case NETR_DELTA_MODIFY_COUNT:
264 d_printf("NETR_DELTA_MODIFY_COUNT not handled\n");
265 break;
266 case NETR_DELTA_DELETE_TRUST:
267 d_printf("NETR_DELTA_DELETE_TRUST not handled\n");
268 break;
269 case NETR_DELTA_DELETE_ACCOUNT:
270 d_printf("NETR_DELTA_DELETE_ACCOUNT not handled\n");
271 break;
272 case NETR_DELTA_DELETE_SECRET:
273 d_printf("NETR_DELTA_DELETE_SECRET not handled\n");
274 break;
275 case NETR_DELTA_DELETE_GROUP2:
276 d_printf("NETR_DELTA_DELETE_GROUP2 not handled\n");
277 break;
278 case NETR_DELTA_DELETE_USER2:
279 d_printf("NETR_DELTA_DELETE_USER2 not handled\n");
280 break;
281 #endif
282 default:
283 printf("unknown delta type 0x%02x\n",
284 r->delta_type);
285 break;
288 return NT_STATUS_OK;
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)
297 int i;
299 for (i = 0; i < r->num_deltas; i++) {
300 display_sam_entry(mem_ctx, database_id, &r->delta_enum[i],
301 ctx);
304 return NT_STATUS_OK;
307 const struct samsync_ops libnet_samsync_display_ops = {
308 .process_objects = display_sam_entries,