⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdbedit.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*    Unix SMB/CIFS implementation.   passdb editing frontend      Copyright (C) Simo Sorce      2000   Copyright (C) Andrew Bartlett 2001      Copyright (C) Jelmer Vernooij 2002   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"#define BIT_BACKEND	0x00000004#define BIT_VERBOSE	0x00000008#define BIT_SPSTYLE	0x00000010#define BIT_CAN_CHANGE	0x00000020#define BIT_MUST_CHANGE	0x00000040#define BIT_RESERV_3	0x00000080#define BIT_FULLNAME	0x00000100#define BIT_HOMEDIR	0x00000200#define BIT_HDIRDRIVE	0x00000400#define BIT_LOGSCRIPT	0x00000800#define BIT_PROFILE	0x00001000#define BIT_MACHINE	0x00002000#define BIT_USERDOMAIN	0x00004000#define BIT_USER	0x00008000#define BIT_LIST	0x00010000#define BIT_MODIFY	0x00020000#define BIT_CREATE	0x00040000#define BIT_DELETE	0x00080000#define BIT_ACCPOLICY	0x00100000#define BIT_ACCPOLVAL	0x00200000#define BIT_ACCTCTRL	0x00400000#define BIT_RESERV_7	0x00800000#define BIT_IMPORT	0x01000000#define BIT_EXPORT	0x02000000#define BIT_FIX_INIT    0x04000000#define BIT_BADPWRESET	0x08000000#define BIT_LOGONHOURS	0x10000000#define MASK_ALWAYS_GOOD	0x0000001F#define MASK_USER_GOOD		0x00405F60/********************************************************* Add all currently available users to another db ********************************************************/static int export_database (struct pdb_context *in, struct pdb_context			    *out, const char *username) {	SAM_ACCOUNT *user = NULL;	DEBUG(3, ("called with username=\"%s\"\n", username));	if (NT_STATUS_IS_ERR(in->pdb_setsampwent(in, 0, 0))) {		fprintf(stderr, "Can't sampwent!\n");		return 1;	}	if (!NT_STATUS_IS_OK(pdb_init_sam(&user))) {		fprintf(stderr, "Can't initialize new SAM_ACCOUNT!\n");		return 1;	}	while (NT_STATUS_IS_OK(in->pdb_getsampwent(in, user))) {		DEBUG(4, ("Processing account %s\n",			  user->private_u.username));		if (!username || 		    (strcmp(username, user->private_u.username)		     == 0)) {			out->pdb_add_sam_account(out, user);			if (!NT_STATUS_IS_OK(pdb_reset_sam(user))) {				fprintf(stderr,					"Can't reset SAM_ACCOUNT!\n");				return 1;			}		}	}	in->pdb_endsampwent(in);	return 0;}/********************************************************* Add all currently available group mappings to another db ********************************************************/static int export_groups (struct pdb_context *in, struct pdb_context *out) {	GROUP_MAP *maps = NULL;	size_t i, entries = 0;	if (NT_STATUS_IS_ERR(in->pdb_enum_group_mapping(in, SID_NAME_UNKNOWN,							&maps, &entries,							False))) {		fprintf(stderr, "Can't get group mappings!\n");		return 1;	}	for (i=0; i<entries; i++) {		out->pdb_add_group_mapping_entry(out, &(maps[i]));	}	SAFE_FREE(maps);	return 0;}/********************************************************* Reset account policies to their default values and remove marker ********************************************************/static int reinit_account_policies (void) {	int i;	for (i=1; decode_account_policy_name(i) != NULL; i++) {		uint32 policy_value;		if (!account_policy_get_default(i, &policy_value)) {			fprintf(stderr, "Can't get default account policy\n");			return -1;		}		if (!account_policy_set(i, policy_value)) {			fprintf(stderr, "Can't set account policy in tdb\n");			return -1;		}	}	if (!remove_account_policy_migrated()) {		fprintf(stderr, "Can't remove marker from tdb\n");		return -1;	}	return 0;}/********************************************************* Add all currently available account policy from tdb to one backend ********************************************************/static int export_account_policies (struct pdb_context *in, struct pdb_context *out) {	int i;	if (!account_policy_migrated(True)) {		fprintf(stderr, "Can't set account policy marker in tdb\n");		return -1;	}	for (i=1; decode_account_policy_name(i) != NULL; i++) {		uint32 policy_value;		if (NT_STATUS_IS_ERR(in->pdb_get_account_policy(in, i, &policy_value))) {			fprintf(stderr, "Can't get account policy from tdb\n");			remove_account_policy_migrated();			return -1;		}		if (NT_STATUS_IS_ERR(out->pdb_set_account_policy(out, i, policy_value))) {			fprintf(stderr, "Can't set account policy in passdb\n");			remove_account_policy_migrated();			return -1;		}	}	return 0;}/********************************************************* Print info from sam structure**********************************************************/static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdstyle){	uid_t uid;	time_t tmp;	/* TODO: chaeck if entry is a user or a workstation */	if (!sam_pwent) return -1;		if (verbosity) {		pstring temp;		const uint8 *hours;				printf ("Unix username:        %s\n", pdb_get_username(sam_pwent));		printf ("NT username:          %s\n", pdb_get_nt_username(sam_pwent));		printf ("Account Flags:        %s\n", pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent), NEW_PW_FORMAT_SPACE_PADDED_LEN));		printf ("User SID:             %s\n",			sid_string_static(pdb_get_user_sid(sam_pwent)));		printf ("Primary Group SID:    %s\n",			sid_string_static(pdb_get_group_sid(sam_pwent)));		printf ("Full Name:            %s\n", pdb_get_fullname(sam_pwent));		printf ("Home Directory:       %s\n", pdb_get_homedir(sam_pwent));		printf ("HomeDir Drive:        %s\n", pdb_get_dir_drive(sam_pwent));		printf ("Logon Script:         %s\n", pdb_get_logon_script(sam_pwent));		printf ("Profile Path:         %s\n", pdb_get_profile_path(sam_pwent));		printf ("Domain:               %s\n", pdb_get_domain(sam_pwent));		printf ("Account desc:         %s\n", pdb_get_acct_desc(sam_pwent));		printf ("Workstations:         %s\n", pdb_get_workstations(sam_pwent));		printf ("Munged dial:          %s\n", pdb_get_munged_dial(sam_pwent));				tmp = pdb_get_logon_time(sam_pwent);		printf ("Logon time:           %s\n", tmp ? http_timestring(tmp) : "0");				tmp = pdb_get_logoff_time(sam_pwent);		printf ("Logoff time:          %s\n", tmp ? http_timestring(tmp) : "0");				tmp = pdb_get_kickoff_time(sam_pwent);		printf ("Kickoff time:         %s\n", tmp ? http_timestring(tmp) : "0");				tmp = pdb_get_pass_last_set_time(sam_pwent);		printf ("Password last set:    %s\n", tmp ? http_timestring(tmp) : "0");				tmp = pdb_get_pass_can_change_time(sam_pwent);		printf ("Password can change:  %s\n", tmp ? http_timestring(tmp) : "0");				tmp = pdb_get_pass_must_change_time(sam_pwent);		printf ("Password must change: %s\n", tmp ? http_timestring(tmp) : "0");		tmp = pdb_get_bad_password_time(sam_pwent);		printf ("Last bad password   : %s\n", tmp ? http_timestring(tmp) : "0");		printf ("Bad password count  : %d\n", 			pdb_get_bad_password_count(sam_pwent));				hours = pdb_get_hours(sam_pwent);		pdb_sethexhours(temp, hours);		printf ("Logon hours         : %s\n", temp);			} else if (smbpwdstyle) {		char lm_passwd[33];		char nt_passwd[33];		uid = nametouid(pdb_get_username(sam_pwent));		pdb_sethexpwd(lm_passwd, pdb_get_lanman_passwd(sam_pwent), pdb_get_acct_ctrl(sam_pwent));		pdb_sethexpwd(nt_passwd, pdb_get_nt_passwd(sam_pwent), pdb_get_acct_ctrl(sam_pwent));					printf("%s:%lu:%s:%s:%s:LCT-%08X:\n",		       pdb_get_username(sam_pwent),		       (unsigned long)uid,		       lm_passwd,		       nt_passwd,		       pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN),		       (uint32)pdb_get_pass_last_set_time(sam_pwent));	} else {		uid = nametouid(pdb_get_username(sam_pwent));		printf ("%s:%lu:%s\n", pdb_get_username(sam_pwent), (unsigned long)uid,				pdb_get_fullname(sam_pwent));	}	return 0;	}/********************************************************* Get an Print User Info**********************************************************/static int print_user_info (struct pdb_context *in, const char *username, BOOL verbosity, BOOL smbpwdstyle){	SAM_ACCOUNT *sam_pwent=NULL;	BOOL ret;	if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) {		return -1;	}	ret = NT_STATUS_IS_OK(in->pdb_getsampwnam (in, sam_pwent, username));	if (ret==False) {		fprintf (stderr, "Username not found!\n");		pdb_free_sam(&sam_pwent);		return -1;	}	ret=print_sam_info (sam_pwent, verbosity, smbpwdstyle);	pdb_free_sam(&sam_pwent);		return ret;}	/********************************************************* List Users**********************************************************/static int print_users_list (struct pdb_context *in, BOOL verbosity, BOOL smbpwdstyle){	SAM_ACCOUNT *sam_pwent=NULL;	BOOL check;		check = NT_STATUS_IS_OK(in->pdb_setsampwent(in, False, 0));	if (!check) {		return 1;	}	check = True;	if (!(NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)))) return 1;	while (check && NT_STATUS_IS_OK(in->pdb_getsampwent (in, sam_pwent))) {		if (verbosity)			printf ("---------------\n");		print_sam_info (sam_pwent, verbosity, smbpwdstyle);		pdb_free_sam(&sam_pwent);		check = NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent));	}	if (check) pdb_free_sam(&sam_pwent);		in->pdb_endsampwent(in);	return 0;}/********************************************************* Fix a list of Users for uninitialised passwords**********************************************************/static int fix_users_list (struct pdb_context *in){	SAM_ACCOUNT *sam_pwent=NULL;	BOOL check;		check = NT_STATUS_IS_OK(in->pdb_setsampwent(in, False, 0));	if (!check) {		return 1;	}	check = True;	if (!(NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)))) return 1;	while (check && NT_STATUS_IS_OK(in->pdb_getsampwent (in, sam_pwent))) {		printf("Updating record for user %s\n", pdb_get_username(sam_pwent));			if (!pdb_update_sam_account(sam_pwent)) {			printf("Update of user %s failed!\n", pdb_get_username(sam_pwent));		}		pdb_free_sam(&sam_pwent);		check = NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent));		if (!check) {			fprintf(stderr, "Failed to initialise new SAM_ACCOUNT structure (out of memory?)\n");		}				}	if (check) pdb_free_sam(&sam_pwent);		in->pdb_endsampwent(in);	return 0;}/********************************************************* Set User Info**********************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -