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

📄 reg_db.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	len = 0;		/* store the number of subkeys */		len += tdb_pack(buffer+len, buflen-len, "d", num_subkeys );		/* pack all the strings */		for (i=0; i<num_subkeys; i++) {		len += tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) );		if ( len > buflen ) {			/* allocate some extra space */			if ((tmpbuf = SMB_REALLOC( buffer, len*2 )) == NULL) {				DEBUG(0,("regdb_store_keys: Failed to realloc memory of size [%d]\n", len*2));				ret = False;				goto done;			}			buffer = tmpbuf;			buflen = len*2;								len = tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) );		}			}		/* finally write out the data */		kbuf.dptr = keyname;	kbuf.dsize = strlen(keyname)+1;	dbuf.dptr = buffer;	dbuf.dsize = len;	if ( tdb_store( tdb_reg, kbuf, dbuf, TDB_REPLACE ) == -1) {		ret = False;		goto done;	}done:			SAFE_FREE( buffer );		return ret;}/*********************************************************************** Store the new subkey record and create any child key records that  do not currently exist ***********************************************************************/BOOL regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr ){	int num_subkeys, i;	pstring path;	REGSUBKEY_CTR *subkeys, *old_subkeys;	char *oldkeyname;		/* fetch a list of the old subkeys so we can determine if any were deleted */		if ( !(old_subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) {		DEBUG(0,("regdb_store_keys: talloc() failure!\n"));		return False;	}	regdb_fetch_keys( key, old_subkeys );		/* store the subkey list for the parent */		if ( !regdb_store_keys_internal( key, ctr ) ) {		DEBUG(0,("regdb_store_keys: Failed to store new subkey list for parent [%s}\n", key ));		return False;	}		/* now delete removed keys */		num_subkeys = regsubkey_ctr_numkeys( old_subkeys );	for ( i=0; i<num_subkeys; i++ ) {		oldkeyname = regsubkey_ctr_specific_key( old_subkeys, i );		if ( !regsubkey_ctr_key_exists( ctr, oldkeyname ) ) {			pstr_sprintf( path, "%s%c%s", key, '/', oldkeyname );			normalize_reg_path( path );			tdb_delete_bystring( tdb_reg, path );		}	}	TALLOC_FREE( old_subkeys );		/* now create records for any subkeys that don't already exist */		num_subkeys = regsubkey_ctr_numkeys( ctr );	for ( i=0; i<num_subkeys; i++ ) {		pstr_sprintf( path, "%s%c%s", key, '/', regsubkey_ctr_specific_key( ctr, i ) );		if ( !(subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) {			DEBUG(0,("regdb_store_keys: talloc() failure!\n"));			return False;		}		if ( regdb_fetch_keys( path, subkeys ) == -1 ) {			/* create a record with 0 subkeys */			if ( !regdb_store_keys_internal( path, subkeys ) ) {				DEBUG(0,("regdb_store_keys: Failed to store new record for key [%s}\n", path ));				TALLOC_FREE( subkeys );				return False;			}		}		TALLOC_FREE( subkeys );	}		return True;}/*********************************************************************** Retrieve an array of strings containing subkeys.  Memory should be  released by the caller.   ***********************************************************************/int regdb_fetch_keys( const char* key, REGSUBKEY_CTR *ctr ){	pstring path;	uint32 num_items;	TDB_DATA dbuf;	char *buf;	uint32 buflen, len;	int i;	fstring subkeyname;	DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL"));		pstrcpy( path, key );		/* convert to key format */	pstring_sub( path, "\\", "/" ); 	strupper_m( path );		dbuf = tdb_fetch_bystring( tdb_reg, path );		buf = dbuf.dptr;	buflen = dbuf.dsize;		if ( !buf ) {		DEBUG(5,("regdb_fetch_keys: tdb lookup failed to locate key [%s]\n", key));		return -1;	}		len = tdb_unpack( buf, buflen, "d", &num_items);		for (i=0; i<num_items; i++) {		len += tdb_unpack( buf+len, buflen-len, "f", subkeyname );		regsubkey_ctr_addkey( ctr, subkeyname );	}	SAFE_FREE( dbuf.dptr );		DEBUG(11,("regdb_fetch_keys: Exit [%d] items\n", num_items));		return num_items;}/**************************************************************************** Unpack a list of registry values frem the TDB ***************************************************************************/ static int regdb_unpack_values(REGVAL_CTR *values, char *buf, int buflen){	int 		len = 0;	uint32		type;	pstring		valuename;	uint32		size;	uint8		*data_p;	uint32 		num_values = 0;	int 		i;				/* loop and unpack the rest of the registry values */		len += tdb_unpack(buf+len, buflen-len, "d", &num_values);		for ( i=0; i<num_values; i++ ) {		/* unpack the next regval */				type = REG_NONE;		size = 0;		data_p = NULL;		len += tdb_unpack(buf+len, buflen-len, "fdB",				  valuename,				  &type,				  &size,				  &data_p);						/* add the new value. Paranoid protective code -- make sure data_p is valid */		if ( size && data_p ) {			regval_ctr_addvalue( values, valuename, type, (const char *)data_p, size );			SAFE_FREE(data_p); /* 'B' option to tdb_unpack does a malloc() */		}		DEBUG(8,("specific: [%s], len: %d\n", valuename, size));	}	return len;}/**************************************************************************** Pack all values in all printer keys ***************************************************************************/ static int regdb_pack_values(REGVAL_CTR *values, char *buf, int buflen){	int 		len = 0;	int 		i;	REGISTRY_VALUE	*val;	int		num_values = regval_ctr_numvals( values );	if ( !values )		return 0;	/* pack the number of values first */		len += tdb_pack( buf+len, buflen-len, "d", num_values );		/* loop over all values */			for ( i=0; i<num_values; i++ ) {					val = regval_ctr_specific_value( values, i );		len += tdb_pack(buf+len, buflen-len, "fdB",				regval_name(val),				regval_type(val),				regval_size(val),				regval_data_p(val) );	}	return len;}/*********************************************************************** Retrieve an array of strings containing subkeys.  Memory should be  released by the caller. ***********************************************************************/int regdb_fetch_values( const char* key, REGVAL_CTR *values ){	TDB_DATA data;	pstring keystr;	DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key));		pstr_sprintf( keystr, "%s/%s", VALUE_PREFIX, key );	normalize_reg_path( keystr );		data = tdb_fetch_bystring( tdb_reg, keystr );		if ( !data.dptr ) {		/* all keys have zero values by default */		return 0;	}		regdb_unpack_values( values, data.dptr, data.dsize );		SAFE_FREE( data.dptr );		return regval_ctr_numvals(values);}/*********************************************************************** Stub function since we do not currently support storing registry  values in the registry.tdb ***********************************************************************/BOOL regdb_store_values( const char *key, REGVAL_CTR *values ){	TDB_DATA data;	pstring keystr;	int len, ret;		DEBUG(10,("regdb_store_values: Looking for value of key [%s] \n", key));		ZERO_STRUCT( data );		len = regdb_pack_values( values, data.dptr, data.dsize );	if ( len <= 0 ) {		DEBUG(0,("regdb_store_values: unable to pack values. len <= 0\n"));		return False;	}		data.dptr = SMB_MALLOC_ARRAY( char, len );	data.dsize = len;		len = regdb_pack_values( values, data.dptr, data.dsize );		SMB_ASSERT( len == data.dsize );		pstr_sprintf( keystr, "%s/%s", VALUE_PREFIX, key );	normalize_reg_path( keystr );		ret = tdb_store_bystring(tdb_reg, keystr, data, TDB_REPLACE);		SAFE_FREE( data.dptr );		return ret != -1 ;}/*  * Table of function pointers for default access */ REGISTRY_OPS regdb_ops = {	regdb_fetch_keys,	regdb_fetch_values,	regdb_store_keys,	regdb_store_values,	NULL};

⌨️ 快捷键说明

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