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

📄 pdb_ldap.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
{	int rc;	LDAPMessage *entry = NULL;	LDAPMod **mods = NULL;	char *name, *dn;	BerElement *ptr = NULL;	rc = ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result);	if (rc != 1) {		DEBUG(0, ("ldapsam_delete_entry: Entry must exist exactly once!\n"));		return NT_STATUS_UNSUCCESSFUL;	}	entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, result);	dn = smbldap_get_dn(ldap_state->smbldap_state->ldap_struct, entry);	if (!dn) {		return NT_STATUS_UNSUCCESSFUL;	}	if (lp_ldap_delete_dn()) {		NTSTATUS ret = NT_STATUS_OK;		rc = smbldap_delete(ldap_state->smbldap_state, dn);		if (rc != LDAP_SUCCESS) {			DEBUG(0, ("ldapsam_delete_entry: Could not delete object %s\n", dn));			ret = NT_STATUS_UNSUCCESSFUL;		}		SAFE_FREE(dn);		return ret;	}	/* Ok, delete only the SAM attributes */		for (name = ldap_first_attribute(ldap_state->smbldap_state->ldap_struct, entry, &ptr);	     name != NULL;	     name = ldap_next_attribute(ldap_state->smbldap_state->ldap_struct, entry, ptr)) {		const char **attrib;		/* We are only allowed to delete the attributes that		   really exist. */		for (attrib = attrs; *attrib != NULL; attrib++) {			/* Don't delete LDAP_ATTR_MOD_TIMESTAMP attribute. */			if (strequal(*attrib, get_userattr_key2string(ldap_state->schema_ver,						LDAP_ATTR_MOD_TIMESTAMP))) {				continue;			}			if (strequal(*attrib, name)) {				DEBUG(10, ("ldapsam_delete_entry: deleting "					   "attribute %s\n", name));				smbldap_set_mod(&mods, LDAP_MOD_DELETE, name,						NULL);			}		}		ldap_memfree(name);	}		if (ptr != NULL) {		ber_free(ptr, 0);	}		smbldap_set_mod(&mods, LDAP_MOD_DELETE, "objectClass", objectclass);	rc = smbldap_modify(ldap_state->smbldap_state, dn, mods);	ldap_mods_free(mods, True);	if (rc != LDAP_SUCCESS) {		char *ld_error = NULL;		ldap_get_option(ldap_state->smbldap_state->ldap_struct, LDAP_OPT_ERROR_STRING,				&ld_error);				DEBUG(0, ("ldapsam_delete_entry: Could not delete attributes for %s, error: %s (%s)\n",			  dn, ldap_err2string(rc), ld_error?ld_error:"unknown"));		SAFE_FREE(ld_error);		SAFE_FREE(dn);		return NT_STATUS_UNSUCCESSFUL;	}	SAFE_FREE(dn);	return NT_STATUS_OK;}		  /* New Interface is being implemented here */#if 0	/* JERRY - not uesed anymore *//**********************************************************************Initialize SAM_ACCOUNT from an LDAP query (unix attributes only)*********************************************************************/static BOOL get_unix_attributes (struct ldapsam_privates *ldap_state, 				SAM_ACCOUNT * sampass,				LDAPMessage * entry,				gid_t *gid){	pstring  homedir;	pstring  temp;	char **ldap_values;	char **values;	if ((ldap_values = ldap_get_values (ldap_state->smbldap_state->ldap_struct, entry, "objectClass")) == NULL) {		DEBUG (1, ("get_unix_attributes: no objectClass! \n"));		return False;	}	for (values=ldap_values;*values;values++) {		if (strequal(*values, LDAP_OBJ_POSIXACCOUNT )) {			break;		}	}		if (!*values) { /*end of array, no posixAccount */		DEBUG(10, ("user does not have %s attributes\n", LDAP_OBJ_POSIXACCOUNT));		ldap_value_free(ldap_values);		return False;	}	ldap_value_free(ldap_values);	if ( !smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 		get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_UNIX_HOME), homedir) ) 	{		return False;	}		if ( !smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 		get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_GIDNUMBER), temp) )	{		return False;	}		*gid = (gid_t)atol(temp);	pdb_set_unix_homedir(sampass, homedir, PDB_SET);		DEBUG(10, ("user has %s attributes\n", LDAP_OBJ_POSIXACCOUNT));		return True;}#endifstatic time_t ldapsam_get_entry_timestamp(	struct ldapsam_privates *ldap_state,	LDAPMessage * entry){	pstring temp;		struct tm tm;	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry,			get_userattr_key2string(ldap_state->schema_ver,LDAP_ATTR_MOD_TIMESTAMP),			temp))		return (time_t) 0;	strptime(temp, "%Y%m%d%H%M%SZ", &tm);	tzset();	return timegm(&tm);}/********************************************************************** Initialize SAM_ACCOUNT from an LDAP query. (Based on init_sam_from_buffer in pdb_tdb.c)*********************************************************************/static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, 				SAM_ACCOUNT * sampass,				LDAPMessage * entry){	time_t  logon_time,			logoff_time,			kickoff_time,			pass_last_set_time, 			pass_can_change_time, 			pass_must_change_time,			ldap_entry_time,			bad_password_time;	pstring 	username, 			domain,			nt_username,			fullname,			homedir,			dir_drive,			logon_script,			profile_path,			acct_desc,			workstations;	char		munged_dial[2048];	uint32 		user_rid; 	uint8 		smblmpwd[LM_HASH_LEN],			smbntpwd[NT_HASH_LEN];	BOOL 		use_samba_attrs = True;	uint16 		acct_ctrl = 0, 			logon_divs;	uint16 		bad_password_count = 0, 			logon_count = 0;	uint32 hours_len;	uint8 		hours[MAX_HOURS_LEN];	pstring temp;	LOGIN_CACHE	*cache_entry = NULL;	uint32 		pwHistLen;	pstring		tmpstring;	BOOL expand_explicit = lp_passdb_expand_explicit();	/*	 * do a little initialization	 */	username[0] 	= '\0';	domain[0] 	= '\0';	nt_username[0] 	= '\0';	fullname[0] 	= '\0';	homedir[0] 	= '\0';	dir_drive[0] 	= '\0';	logon_script[0] = '\0';	profile_path[0] = '\0';	acct_desc[0] 	= '\0';	munged_dial[0] 	= '\0';	workstations[0] = '\0';	 	if (sampass == NULL || ldap_state == NULL || entry == NULL) {		DEBUG(0, ("init_sam_from_ldap: NULL parameters found!\n"));		return False;	}	if (ldap_state->smbldap_state->ldap_struct == NULL) {		DEBUG(0, ("init_sam_from_ldap: ldap_state->smbldap_state->ldap_struct is NULL!\n"));		return False;	}		if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, "uid", username)) {		DEBUG(1, ("init_sam_from_ldap: No uid attribute found for this user!\n"));		return False;	}	DEBUG(2, ("init_sam_from_ldap: Entry found for user: %s\n", username));	pstrcpy(nt_username, username);	pstrcpy(domain, ldap_state->domain_name);		pdb_set_username(sampass, username, PDB_SET);	pdb_set_domain(sampass, domain, PDB_DEFAULT);	pdb_set_nt_username(sampass, nt_username, PDB_SET);	/* deal with different attributes between the schema first */		if ( ldap_state->schema_ver == SCHEMAVER_SAMBASAMACCOUNT ) {		if (smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 				get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_USER_SID), temp)) {			pdb_set_user_sid_from_string(sampass, temp, PDB_SET);		}				if (smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 				get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PRIMARY_GROUP_SID), temp)) {			pdb_set_group_sid_from_string(sampass, temp, PDB_SET);					} else {			pdb_set_group_sid_from_rid(sampass, DOMAIN_GROUP_RID_USERS, PDB_DEFAULT);		}	} else {		if (smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry,				get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_USER_RID), temp)) {			user_rid = (uint32)atol(temp);			pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET);		}				if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 				get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PRIMARY_GROUP_RID), temp)) {			pdb_set_group_sid_from_rid(sampass, DOMAIN_GROUP_RID_USERS, PDB_DEFAULT);		} else {			uint32 group_rid;						group_rid = (uint32)atol(temp);						/* for some reason, we often have 0 as a primary group RID.			   Make sure that we treat this just as a 'default' value */			   			if ( group_rid > 0 )				pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET);			else				pdb_set_group_sid_from_rid(sampass, DOMAIN_GROUP_RID_USERS, PDB_DEFAULT);		}	}	if (pdb_get_init_flags(sampass,PDB_USERSID) == PDB_DEFAULT) {		DEBUG(1, ("init_sam_from_ldap: no %s or %s attribute found for this user %s\n", 			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_USER_SID),			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_USER_RID),			username));		return False;	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PWD_LAST_SET), temp)) {		/* leave as default */	} else {		pass_last_set_time = (time_t) atol(temp);		pdb_set_pass_last_set_time(sampass, pass_last_set_time, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LOGON_TIME), temp)) {		/* leave as default */	} else {		logon_time = (time_t) atol(temp);		pdb_set_logon_time(sampass, logon_time, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LOGOFF_TIME), temp)) {		/* leave as default */	} else {		logoff_time = (time_t) atol(temp);		pdb_set_logoff_time(sampass, logoff_time, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_KICKOFF_TIME), temp)) {		/* leave as default */	} else {		kickoff_time = (time_t) atol(temp);		pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PWD_CAN_CHANGE), temp)) {		/* leave as default */	} else {		pass_can_change_time = (time_t) atol(temp);		pdb_set_pass_can_change_time(sampass, pass_can_change_time, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PWD_MUST_CHANGE), temp)) {			/* leave as default */	} else {		pass_must_change_time = (time_t) atol(temp);		pdb_set_pass_must_change_time(sampass, pass_must_change_time, PDB_SET);	}	/* recommend that 'gecos' and 'displayName' should refer to the same	 * attribute OID.  userFullName depreciated, only used by Samba	 * primary rules of LDAP: don't make a new attribute when one is already defined	 * that fits your needs; using cn then displayName rather than 'userFullName'	 */	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry,			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_DISPLAY_NAME), fullname)) {		if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry,				get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_CN), fullname)) {			/* leave as default */		} else {			pdb_set_fullname(sampass, fullname, PDB_SET);		}	} else {		pdb_set_fullname(sampass, fullname, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry, 			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_HOME_DRIVE), dir_drive)) 	{		pdb_set_dir_drive( sampass, lp_logon_drive(), PDB_DEFAULT );	} else {		pdb_set_dir_drive(sampass, dir_drive, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry,			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_HOME_PATH), homedir)) 	{		pdb_set_homedir( sampass, 			talloc_sub_basic(sampass->mem_ctx, username, lp_logon_home()),			PDB_DEFAULT );	} else {		pstrcpy( tmpstring, homedir );		if (expand_explicit) {			standard_sub_basic( username, tmpstring,					    sizeof(tmpstring) );		}		pdb_set_homedir(sampass, tmpstring, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry,			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LOGON_SCRIPT), logon_script)) 	{		pdb_set_logon_script( sampass, 			talloc_sub_basic(sampass->mem_ctx, username, lp_logon_script()), 			PDB_DEFAULT );	} else {		pstrcpy( tmpstring, logon_script );		if (expand_explicit) {			standard_sub_basic( username, tmpstring,					    sizeof(tmpstring) );		}		pdb_set_logon_script(sampass, tmpstring, PDB_SET);	}	if (!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry,			get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PROFILE_PATH), profile_path)) 	{		pdb_set_profile_path( sampass, 			talloc_sub_basic( sampass->mem_ctx, username, lp_logon_path()),			PDB_DEFAULT );	} else {		pstrcpy( tmpstring, profile_path );		if (expand_explicit) {

⌨️ 快捷键说明

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