Esempio n. 1
0
static int key_forms_fetch_values( const char *key, REGVAL_CTR *values )
{
	uint32 		data[8];
	int		i, num_values, form_index = 1;
	nt_forms_struct *forms_list = NULL;
	nt_forms_struct *form;
		
	DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" ));
	
	num_values = get_ntforms( &forms_list );
		
	DEBUG(10,("hive_forms_fetch_values: [%d] user defined forms returned\n",
		num_values));

	/* handle user defined forms */
				
	for ( i=0; i<num_values; i++ ) {
		form = &forms_list[i];
			
		data[0] = form->width;
		data[1] = form->length;
		data[2] = form->left;
		data[3] = form->top;
		data[4] = form->right;
		data[5] = form->bottom;
		data[6] = form_index++;
		data[7] = form->flag;
			
		regval_ctr_addvalue( values, form->name, REG_BINARY, (char*)data, sizeof(data) );	
	}
		
	SAFE_FREE( forms_list );
	forms_list = NULL;
		
	/* handle built-on forms */
		
	num_values = get_builtin_ntforms( &forms_list );
		
	DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
		num_values));
			
	for ( i=0; i<num_values; i++ ) {
		form = &forms_list[i];
			
		data[0] = form->width;
		data[1] = form->length;
		data[2] = form->left;
		data[3] = form->top;
		data[4] = form->right;
		data[5] = form->bottom;
		data[6] = form_index++;
		data[7] = form->flag;
					
		regval_ctr_addvalue( values, form->name, REG_BINARY, (char*)data, sizeof(data) );
	}
		
	SAFE_FREE( forms_list );
	
	return regval_ctr_numvals( values );
}
static int hkpt_params_fetch_values(const char *key, REGVAL_CTR *regvals)
{
	uint32 base_index;
	uint32 buffer_size;
	char *buffer = NULL;

	/* This is ALMOST the same as perflib_009_params, but HKPT has
	   a "Counters" entry instead of a "Counter" key. <Grrrr> */

	base_index = reg_perfcount_get_base_index();
	buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
	regval_ctr_addvalue(regvals, "Counters", REG_MULTI_SZ, buffer,
			    buffer_size);

	if(buffer_size > 0) {
		SAFE_FREE(buffer);
	}

	buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
	regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
	if(buffer_size > 0) {
		SAFE_FREE(buffer);
	}

	return regval_ctr_numvals( regvals );
}
static int prod_options_fetch_values(const char *key, REGVAL_CTR *regvals)
{
	const char *value_ascii = "";
	fstring value;
	int value_length;

	switch (lp_server_role()) {
		case ROLE_DOMAIN_PDC:
		case ROLE_DOMAIN_BDC:
			value_ascii = "LanmanNT";
			break;
		case ROLE_STANDALONE:
			value_ascii = "ServerNT";
			break;
		case ROLE_DOMAIN_MEMBER:
			value_ascii = "WinNT";
			break;
	}

	value_length = push_ucs2(value, value, value_ascii, sizeof(value),
				 STR_TERMINATE|STR_NOALIGN );
	regval_ctr_addvalue(regvals, "ProductType", REG_SZ, value,
			    value_length);

	return regval_ctr_numvals( regvals );
}
Esempio n. 4
0
static int perflib_params(struct regval_ctr *regvals)
{
	int base_index = -1;
	int last_counter = -1;
	int last_help = -1;
	int version = 0x00010001;
	
	base_index = reg_perfcount_get_base_index();
	regval_ctr_addvalue(regvals, "Base Index", REG_DWORD, (uint8_t *)&base_index, sizeof(base_index));
	last_counter = reg_perfcount_get_last_counter(base_index);
	regval_ctr_addvalue(regvals, "Last Counter", REG_DWORD, (uint8_t *)&last_counter, sizeof(last_counter));
	last_help = reg_perfcount_get_last_help(last_counter);
	regval_ctr_addvalue(regvals, "Last Help", REG_DWORD, (uint8_t *)&last_help, sizeof(last_help));
	regval_ctr_addvalue(regvals, "Version", REG_DWORD, (uint8_t *)&version, sizeof(version));

	return regval_ctr_numvals( regvals );
}
Esempio n. 5
0
static int perflib_009_params(struct regval_ctr *regvals)
{
	int base_index;
	int buffer_size;
	char *buffer = NULL;

	base_index = reg_perfcount_get_base_index();
	buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
	regval_ctr_addvalue(regvals, "Counter", REG_MULTI_SZ, (uint8_t *)buffer, buffer_size);
	if(buffer_size > 0)
		SAFE_FREE(buffer);
	buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
	regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, (uint8_t *)buffer, buffer_size);
	if(buffer_size > 0)
		SAFE_FREE(buffer);
	
	return regval_ctr_numvals( regvals );
}
Esempio n. 6
0
static void regdb_ctr_add_value(struct regval_ctr *ctr,
				struct builtin_regkey_value *value)
{
	switch(value->type) {
	case REG_DWORD:
		regval_ctr_addvalue(ctr, value->valuename, REG_DWORD,
				    (uint8_t *)&value->data.dw_value,
				    sizeof(uint32));
		break;

	case REG_SZ:
		regval_ctr_addvalue_sz(ctr, value->valuename,
				       value->data.string);
		break;

	default:
		DEBUG(0, ("regdb_ctr_add_value: invalid value type in "
			  "registry values [%d]\n", value->type));
	}
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
                                REGF_NK_REC *parent, REGF_FILE *outfile,
                                const char *parentpath  )
{
	REGF_NK_REC *key, *subkey;
	struct security_descriptor *new_sd;
	struct regval_ctr *values;
	struct regsubkey_ctr *subkeys;
	int i;
	char *path;
	WERROR werr;

	/* swap out the SIDs in the security descriptor */

	if ( !(new_sd = dup_sec_desc( outfile->mem_ctx, nk->sec_desc->sec_desc )) ) {
		fprintf( stderr, "Failed to copy security descriptor!\n" );
		return False;
	}

	verbose_output("ACL for %s%s%s\n", parentpath, parent ? "\\" : "", nk->keyname);
	swap_sid_in_acl( new_sd, &old_sid, &new_sid );

	werr = regsubkey_ctr_init(NULL, &subkeys);
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(0,("copy_registry_tree: talloc() failure!\n"));
		return False;
	}

	werr = regval_ctr_init(subkeys, &values);
	if (!W_ERROR_IS_OK(werr)) {
		TALLOC_FREE( subkeys );
		DEBUG(0,("copy_registry_tree: talloc() failure!\n"));
		return False;
	}

	/* copy values into the struct regval_ctr */

	for ( i=0; i<nk->num_values; i++ ) {
		regval_ctr_addvalue( values, nk->values[i].valuename, nk->values[i].type,
			nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
	}

	/* copy subkeys into the struct regsubkey_ctr */

	while ( (subkey = regfio_fetch_subkey( infile, nk )) ) {
		regsubkey_ctr_addkey( subkeys, subkey->keyname );
	}

	key = regfio_write_key( outfile, nk->keyname, values, subkeys, new_sd, parent );

	/* write each one of the subkeys out */

	path = talloc_asprintf(subkeys, "%s%s%s",
			parentpath, parent ? "\\" : "",nk->keyname);
	if (!path) {
		TALLOC_FREE( subkeys );
		return false;
	}

	nk->subkey_index = 0;
	while ((subkey = regfio_fetch_subkey(infile, nk))) {
		if (!copy_registry_tree( infile, subkey, key, outfile, path)) {
			TALLOC_FREE(subkeys);
			return false;
		}
	}


	verbose_output("[%s]\n", path);

	/* values is a talloc()'d child of subkeys here so just throw it all away */
	TALLOC_FREE(subkeys);

	return True;
}
Esempio n. 9
0
static void fill_in_driver_values( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3, REGVAL_CTR *values )
{
	char *buffer = NULL;
	int buffer_size = 0;
	int i, length;
	char *filename;
	UNISTR2	data;
	
	filename = dos_basename( info3->driverpath );
	init_unistr2( &data, filename, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Driver", REG_SZ, (char*)data.buffer, 
		data.uni_str_len*sizeof(uint16) );
	
	filename = dos_basename( info3->configfile );
	init_unistr2( &data, filename, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Configuration File", REG_SZ, (char*)data.buffer, 
		data.uni_str_len*sizeof(uint16) );
	
	filename = dos_basename( info3->datafile );
	init_unistr2( &data, filename, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Data File", REG_SZ, (char*)data.buffer, 
		data.uni_str_len*sizeof(uint16) );
	
	filename = dos_basename( info3->helpfile );
	init_unistr2( &data, filename, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Help File", REG_SZ, (char*)data.buffer, 
		data.uni_str_len*sizeof(uint16) );
	
	init_unistr2( &data, info3->defaultdatatype, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Data Type", REG_SZ, (char*)data.buffer, 
		data.uni_str_len*sizeof(uint16) );
	
	regval_ctr_addvalue( values, "Version", REG_DWORD, (char*)&info3->cversion, 
		sizeof(info3->cversion) );
	
	if ( info3->dependentfiles ) {
		/* place the list of dependent files in a single 
		   character buffer, separating each file name by
		   a NULL */
		   
		for ( i=0; strcmp(info3->dependentfiles[i], ""); i++ ) {
			/* strip the path to only the file's base name */
		
			filename = dos_basename( info3->dependentfiles[i] );
			
			length = strlen(filename);
		
			buffer = (char *)SMB_REALLOC( buffer, buffer_size + (length + 1)*sizeof(uint16) );
			if ( !buffer ) {
				break;
			}
			
			init_unistr2( &data, filename, UNI_STR_TERMINATE);
			memcpy( buffer+buffer_size, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
		
			buffer_size += (length + 1)*sizeof(uint16);
		}
		
		/* terminated by double NULL.  Add the final one here */
		
		buffer = (char *)SMB_REALLOC( buffer, buffer_size + 2 );
		if ( !buffer ) {
			buffer_size = 0;
		} else {
			buffer[buffer_size++] = '\0';
			buffer[buffer_size++] = '\0';
		}
	}
	
	regval_ctr_addvalue( values, "Dependent Files",    REG_MULTI_SZ, buffer, buffer_size );
		
	SAFE_FREE( buffer );
	
	return;
}
Esempio n. 10
0
static void fill_in_printer_values( NT_PRINTER_INFO_LEVEL_2 *info2, REGVAL_CTR *values )
{
	DEVICEMODE	*devmode;
	prs_struct	prs;
	uint32		offset;
	UNISTR2		data;
	char 		*p;
	uint32 printer_status = PRINTER_STATUS_OK;
	
	regval_ctr_addvalue( values, "Attributes",       REG_DWORD, (char*)&info2->attributes,       sizeof(info2->attributes) );
	regval_ctr_addvalue( values, "Priority",         REG_DWORD, (char*)&info2->priority,         sizeof(info2->attributes) );
	regval_ctr_addvalue( values, "ChangeID",         REG_DWORD, (char*)&info2->changeid,         sizeof(info2->changeid) );
	regval_ctr_addvalue( values, "Default Priority", REG_DWORD, (char*)&info2->default_priority, sizeof(info2->default_priority) );
	
	/* lie and say everything is ok since we don't want to call print_queue_length() to get the real status */
	regval_ctr_addvalue( values, "Status",           REG_DWORD, (char*)&printer_status,          sizeof(info2->status) );

	regval_ctr_addvalue( values, "StartTime",        REG_DWORD, (char*)&info2->starttime,        sizeof(info2->starttime) );
	regval_ctr_addvalue( values, "UntilTime",        REG_DWORD, (char*)&info2->untiltime,        sizeof(info2->untiltime) );

	/* strip the \\server\ from this string */
	if ( !(p = strrchr( info2->printername, '\\' ) ) )
		p = info2->printername;
	else
		p++;
	init_unistr2( &data, p, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Name", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->location, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Location", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->comment, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Description", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->parameters, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Parameters", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->portname, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Port", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->sharename, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Share Name", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->drivername, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Printer Driver", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->sepfile, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Separator File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, "WinPrint", UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Print Processor",  REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, "RAW", UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Datatype", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

		
	/* use a prs_struct for converting the devmode and security 
	   descriptor to REG_BINARY */
	
	prs_init( &prs, RPC_MAX_PDU_FRAG_LEN, values, MARSHALL);

	/* stream the device mode */
		
	if ( (devmode = construct_dev_mode( info2->sharename )) != NULL ) {
		if ( spoolss_io_devmode( "devmode", &prs, 0, devmode ) ) {
			offset = prs_offset( &prs );
			regval_ctr_addvalue( values, "Default Devmode", REG_BINARY, prs_data_p(&prs), offset );
		}
	}
		
	prs_mem_clear( &prs );
	prs_set_offset( &prs, 0 );
		
	/* stream the printer security descriptor */
	
	if ( info2->secdesc_buf && info2->secdesc_buf->len )  {
		if ( sec_io_desc("sec_desc", &info2->secdesc_buf->sec, &prs, 0 ) ) {
			offset = prs_offset( &prs );
			regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&prs), offset );
		}
	}

	prs_mem_free( &prs );

	return;		
}
Esempio n. 11
0
bool eventlog_init_keys(void)
{
    /* Find all of the eventlogs, add keys for each of them */
    const char **elogs = lp_eventlog_list();
    char *evtlogpath = NULL;
    char *evtfilepath = NULL;
    struct regsubkey_ctr *subkeys;
    REGVAL_CTR *values;
    uint32 uiMaxSize;
    uint32 uiRetention;
    uint32 uiCategoryCount;
    UNISTR2 data;
    TALLOC_CTX *ctx = talloc_tos();
    WERROR werr;

    while (elogs && *elogs) {
        werr = regsubkey_ctr_init(ctx, &subkeys);
        if (!W_ERROR_IS_OK(werr)) {
            DEBUG( 0, ( "talloc() failure!\n" ) );
            return False;
        }
        regdb_fetch_keys(KEY_EVENTLOG, subkeys);
        regsubkey_ctr_addkey( subkeys, *elogs );
        if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
            TALLOC_FREE(subkeys);
            return False;
        }
        TALLOC_FREE(subkeys);

        /* add in the key of form KEY_EVENTLOG/Application */
        DEBUG( 5,
               ( "Adding key of [%s] to path of [%s]\n", *elogs,
                 KEY_EVENTLOG ) );

        evtlogpath = talloc_asprintf(ctx, "%s\\%s",
                                     KEY_EVENTLOG, *elogs);
        if (!evtlogpath) {
            return false;
        }
        /* add in the key of form KEY_EVENTLOG/Application/Application */
        DEBUG( 5,
               ( "Adding key of [%s] to path of [%s]\n", *elogs,
                 evtlogpath ) );
        werr = regsubkey_ctr_init(ctx, &subkeys);
        if (!W_ERROR_IS_OK(werr)) {
            DEBUG( 0, ( "talloc() failure!\n" ) );
            return False;
        }
        regdb_fetch_keys( evtlogpath, subkeys );
        regsubkey_ctr_addkey( subkeys, *elogs );

        if ( !regdb_store_keys( evtlogpath, subkeys ) ) {
            TALLOC_FREE(subkeys);
            return False;
        }
        TALLOC_FREE( subkeys );

        /* now add the values to the KEY_EVENTLOG/Application form key */
        if (!(values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
            DEBUG( 0, ( "talloc() failure!\n" ) );
            return False;
        }
        DEBUG( 5,
               ( "Storing values to eventlog path of [%s]\n",
                 evtlogpath ) );
        regdb_fetch_values( evtlogpath, values );


        if (!regval_ctr_key_exists(values, "MaxSize")) {

            /* assume we have none, add them all */

            /* hard code some initial values */

            /* uiDisplayNameId = 0x00000100; */
            uiMaxSize = 0x00080000;
            uiRetention = 0x93A80;

            regval_ctr_addvalue(values, "MaxSize", REG_DWORD,
                                (char *)&uiMaxSize,
                                sizeof(uint32));

            regval_ctr_addvalue(values, "Retention", REG_DWORD,
                                (char *)&uiRetention,
                                sizeof(uint32));
            init_unistr2(&data, *elogs, UNI_STR_TERMINATE);

            regval_ctr_addvalue(values, "PrimaryModule", REG_SZ,
                                (char *)data.buffer,
                                data.uni_str_len *
                                sizeof(uint16));
            init_unistr2(&data, *elogs, UNI_STR_TERMINATE);

            regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ,
                                (char *)data.buffer,
                                data.uni_str_len *
                                sizeof(uint16));

            evtfilepath = talloc_asprintf(ctx,
                                          "%%SystemRoot%%\\system32\\config\\%s.tdb",
                                          *elogs);
            if (!evtfilepath) {
                TALLOC_FREE(values);
            }
            init_unistr2(&data, evtfilepath, UNI_STR_TERMINATE);
            regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, (char *)data.buffer,
                                data.uni_str_len * sizeof(uint16));
            regdb_store_values(evtlogpath, values);

        }

        TALLOC_FREE(values);

        /* now do the values under KEY_EVENTLOG/Application/Application */
        TALLOC_FREE(evtlogpath);
        evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
                                     KEY_EVENTLOG, *elogs, *elogs);
        if (!evtlogpath) {
            return false;
        }
        if (!(values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
            DEBUG( 0, ( "talloc() failure!\n" ) );
            return False;
        }
        DEBUG( 5,
               ( "Storing values to eventlog path of [%s]\n",
                 evtlogpath));
        regdb_fetch_values(evtlogpath, values);
        if (!regval_ctr_key_exists( values, "CategoryCount")) {

            /* hard code some initial values */

            uiCategoryCount = 0x00000007;
            regval_ctr_addvalue( values, "CategoryCount",
                                 REG_DWORD,
                                 ( char * ) &uiCategoryCount,
                                 sizeof( uint32 ) );
            init_unistr2( &data,
                          "%SystemRoot%\\system32\\eventlog.dll",
                          UNI_STR_TERMINATE );

            regval_ctr_addvalue( values, "CategoryMessageFile",
                                 REG_EXPAND_SZ,
                                 ( char * ) data.buffer,
                                 data.uni_str_len *
                                 sizeof( uint16 ) );
            regdb_store_values( evtlogpath, values );
        }
        TALLOC_FREE(values);
        elogs++;
    }

    return true;
}
Esempio n. 12
0
bool eventlog_add_source( const char *eventlog, const char *sourcename,
                          const char *messagefile )
{
    /* Find all of the eventlogs, add keys for each of them */
    /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
       need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */

    const char **elogs = lp_eventlog_list(  );
    char **wrklist, **wp;
    char *evtlogpath = NULL;
    struct regsubkey_ctr *subkeys;
    REGVAL_CTR *values;
    REGISTRY_VALUE *rval;
    UNISTR2 data;
    uint16 *msz_wp;
    int mbytes, ii;
    bool already_in;
    int i;
    int numsources;
    TALLOC_CTX *ctx = talloc_tos();
    WERROR werr;

    if (!elogs) {
        return False;
    }

    for ( i = 0; elogs[i]; i++ ) {
        if ( strequal( elogs[i], eventlog ) )
            break;
    }

    if ( !elogs[i] ) {
        DEBUG( 0,
               ( "Eventlog [%s] not found in list of valid event logs\n",
                 eventlog ) );
        return false;	/* invalid named passed in */
    }

    /* have to assume that the evenlog key itself exists at this point */
    /* add in a key of [sourcename] under the eventlog key */

    /* todo add to Sources */

    if (!( values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
        DEBUG( 0, ( "talloc() failure!\n" ));
        return false;
    }

    evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog);
    if (!evtlogpath) {
        TALLOC_FREE(values);
        return false;
    }

    regdb_fetch_values( evtlogpath, values );


    if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
        DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
        return False;
    }
    /* perhaps this adding a new string to a multi_sz should be a fn? */
    /* check to see if it's there already */

    if ( rval->type != REG_MULTI_SZ ) {
        DEBUG( 0,
               ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
        return False;
    }
    /* convert to a 'regulah' chars to do some comparisons */

    already_in = False;
    wrklist = NULL;
    dump_data( 1, rval->data_p, rval->size );
    if ( ( numsources =
                regval_convert_multi_sz( ( uint16 * ) rval->data_p, rval->size,
                                         &wrklist ) ) > 0 ) {

        ii = numsources;
        /* see if it's in there already */
        wp = wrklist;

        while ( ii && wp && *wp ) {
            if ( strequal( *wp, sourcename ) ) {
                DEBUG( 5,
                       ( "Source name [%s] already in list for [%s] \n",
                         sourcename, eventlog ) );
                already_in = True;
                break;
            }
            wp++;
            ii--;
        }
    } else {
        if ( numsources < 0 ) {
            DEBUG( 3, ( "problem in getting the sources\n" ) );
            return False;
        }
        DEBUG( 3,
               ( "Nothing in the sources list, this might be a problem\n" ) );
    }

    wp = wrklist;

    if ( !already_in ) {
        /* make a new list with an additional entry; copy values, add another */
        wp = TALLOC_ARRAY(ctx, char *, numsources + 2 );

        if ( !wp ) {
            DEBUG( 0, ( "talloc() failed \n" ) );
            return False;
        }
        memcpy( wp, wrklist, sizeof( char * ) * numsources );
        *( wp + numsources ) = ( char * ) sourcename;
        *( wp + numsources + 1 ) = NULL;
        mbytes = regval_build_multi_sz( wp, &msz_wp );
        dump_data( 1, ( uint8 * ) msz_wp, mbytes );
        regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
                             ( char * ) msz_wp, mbytes );
        regdb_store_values( evtlogpath, values );
        TALLOC_FREE(msz_wp);
    } else {
Esempio n. 13
0
static BOOL init_registry_data( void )
{
	pstring path, base, remaining;
	fstring keyname, subkeyname;
	REGSUBKEY_CTR *subkeys;
	REGVAL_CTR *values;
	int i;
	const char *p, *p2;
	UNISTR2 data;

	/*
	 * There are potentially quite a few store operations which are all
	 * indiviually wrapped in tdb transactions. Wrapping them in a single
	 * transaction gives just a single transaction_commit() to actually do
	 * its fsync()s. See tdb/common/transaction.c for info about nested
	 * transaction behaviour.
	 */

	if ( tdb_transaction_start( tdb_reg ) == -1 ) {
		DEBUG(0, ("init_registry_data: tdb_transaction_start "
			  "failed\n"));
		return False;
	}
	
	/* loop over all of the predefined paths and add each component */
	
	for ( i=0; builtin_registry_paths[i] != NULL; i++ ) {

		DEBUG(6,("init_registry_data: Adding [%s]\n", builtin_registry_paths[i]));

		pstrcpy( path, builtin_registry_paths[i] );
		pstrcpy( base, "" );
		p = path;
		
		while ( next_token(&p, keyname, "\\", sizeof(keyname)) ) {
		
			/* build up the registry path from the components */
			
			if ( *base )
				pstrcat( base, "\\" );
			pstrcat( base, keyname );
			
			/* get the immediate subkeyname (if we have one ) */
			
			*subkeyname = '\0';
			if ( *p ) {
				pstrcpy( remaining, p );
				p2 = remaining;
				
				if ( !next_token(&p2, subkeyname, "\\", sizeof(subkeyname)) )
					fstrcpy( subkeyname, p2 );
			}

			DEBUG(10,("init_registry_data: Storing key [%s] with subkey [%s]\n",
				base, *subkeyname ? subkeyname : "NULL"));
			
			/* we don't really care if the lookup succeeds or not since
			   we are about to update the record.  We just want any 
			   subkeys already present */
			
			if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) {
				DEBUG(0,("talloc() failure!\n"));
				goto fail;
			}

			regdb_fetch_keys( base, subkeys );
			if ( *subkeyname ) 
				regsubkey_ctr_addkey( subkeys, subkeyname );
			if ( !regdb_store_keys( base, subkeys ))
				goto fail;
			
			TALLOC_FREE( subkeys );
		}
	}

	/* loop over all of the predefined values and add each component */
	
	for ( i=0; builtin_registry_values[i].path != NULL; i++ ) {
		if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
			DEBUG(0,("talloc() failure!\n"));
			goto fail;
		}

		regdb_fetch_values( builtin_registry_values[i].path, values );

		/* preserve existing values across restarts.  Only add new ones */

		if ( !regval_ctr_key_exists( values, builtin_registry_values[i].valuename ) ) 
		{
			switch( builtin_registry_values[i].type ) {
			case REG_DWORD:
				regval_ctr_addvalue( values, 
				                     builtin_registry_values[i].valuename,
						     REG_DWORD,
						     (char*)&builtin_registry_values[i].data.dw_value,
						     sizeof(uint32) );
				break;
				
			case REG_SZ:
				init_unistr2( &data, builtin_registry_values[i].data.string, UNI_STR_TERMINATE);
				regval_ctr_addvalue( values, 
				                     builtin_registry_values[i].valuename,
						     REG_SZ,
						     (char*)data.buffer,
						     data.uni_str_len*sizeof(uint16) );
				break;
			
			default:
				DEBUG(0,("init_registry_data: invalid value type in builtin_registry_values [%d]\n",
					builtin_registry_values[i].type));
			}
			regdb_store_values( builtin_registry_values[i].path, values );
		}
		
		TALLOC_FREE( values );
	}
	
	if (tdb_transaction_commit( tdb_reg ) == -1) {
		DEBUG(0, ("init_registry_data: Could not commit "
			  "transaction\n"));
		return False;
	}

	return True;

 fail:

	if (tdb_transaction_cancel( tdb_reg ) == -1) {
		smb_panic("init_registry_data: tdb_transaction_cancel "
			  "failed\n");
	}

	return False;
}
Esempio n. 14
0
static void fill_in_printer_values( NT_PRINTER_INFO_LEVEL_2 *info2, REGVAL_CTR *values )
{
	struct spoolss_DeviceMode *devmode;
	UNISTR2		data;
	char 		*p;
	uint32 printer_status = PRINTER_STATUS_OK;
	
	regval_ctr_addvalue( values, "Attributes",       REG_DWORD, (char*)&info2->attributes,       sizeof(info2->attributes) );
	regval_ctr_addvalue( values, "Priority",         REG_DWORD, (char*)&info2->priority,         sizeof(info2->attributes) );
	regval_ctr_addvalue( values, "ChangeID",         REG_DWORD, (char*)&info2->changeid,         sizeof(info2->changeid) );
	regval_ctr_addvalue( values, "Default Priority", REG_DWORD, (char*)&info2->default_priority, sizeof(info2->default_priority) );
	
	/* lie and say everything is ok since we don't want to call print_queue_length() to get the real status */
	regval_ctr_addvalue( values, "Status",           REG_DWORD, (char*)&printer_status,          sizeof(info2->status) );

	regval_ctr_addvalue( values, "StartTime",        REG_DWORD, (char*)&info2->starttime,        sizeof(info2->starttime) );
	regval_ctr_addvalue( values, "UntilTime",        REG_DWORD, (char*)&info2->untiltime,        sizeof(info2->untiltime) );

	/* strip the \\server\ from this string */
	if ( !(p = strrchr( info2->printername, '\\' ) ) )
		p = info2->printername;
	else
		p++;
	init_unistr2( &data, p, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Name", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->location, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Location", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->comment, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Description", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->parameters, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Parameters", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->portname, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Port", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->sharename, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Share Name", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->drivername, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Printer Driver", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, info2->sepfile, UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Separator File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, "WinPrint", UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Print Processor",  REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	init_unistr2( &data, "RAW", UNI_STR_TERMINATE);
	regval_ctr_addvalue( values, "Datatype", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );

	/* stream the device mode */

	devmode = construct_dev_mode(values,info2->sharename);
	if (devmode) {
		DATA_BLOB blob;
		enum ndr_err_code ndr_err;

		ndr_err = ndr_push_struct_blob(&blob, values, NULL, devmode,
				(ndr_push_flags_fn_t)ndr_push_spoolss_DeviceMode);

		if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
			regval_ctr_addvalue(values, "Default Devmode", REG_BINARY,
					    (const char *)blob.data, blob.length);
		}
	}

	/* stream the printer security descriptor */

	if (info2->secdesc_buf &&
	    info2->secdesc_buf->sd &&
	    info2->secdesc_buf->sd_size)
	{
		NTSTATUS status;
		DATA_BLOB blob;

		status = marshall_sec_desc(values, info2->secdesc_buf->sd,
					   &blob.data, &blob.length);
		if (NT_STATUS_IS_OK(status)) {
			regval_ctr_addvalue(values, "Security", REG_BINARY,
					    (const char *)blob.data, blob.length);
		}
	}

	return;
}
Esempio n. 15
0
static WERROR reg_load_tree(REGF_FILE *regfile, const char *topkeypath,
			    REGF_NK_REC *key)
{
	REGF_NK_REC *subkey;
	struct registry_key_handle registry_key;
	struct regval_ctr *values;
	struct regsubkey_ctr *subkeys;
	int i;
	char *path = NULL;
	WERROR result = WERR_OK;

	/* initialize the struct registry_key_handle structure */

	registry_key.ops = reghook_cache_find(topkeypath);
	if (!registry_key.ops) {
		DEBUG(0, ("reg_load_tree: Failed to assign registry_ops "
			  "to [%s]\n", topkeypath));
		return WERR_BADFILE;
	}

	registry_key.name = talloc_strdup(regfile->mem_ctx, topkeypath);
	if (!registry_key.name) {
		DEBUG(0, ("reg_load_tree: Talloc failed for reg_key.name!\n"));
		return WERR_NOMEM;
	}

	/* now start parsing the values and subkeys */

	result = regsubkey_ctr_init(regfile->mem_ctx, &subkeys);
	W_ERROR_NOT_OK_RETURN(result);

	result = regval_ctr_init(subkeys, &values);
	W_ERROR_NOT_OK_RETURN(result);

	/* copy values into the struct regval_ctr */

	for (i=0; i<key->num_values; i++) {
		regval_ctr_addvalue(values, key->values[i].valuename,
				    key->values[i].type,
				    key->values[i].data,
				    (key->values[i].data_size & ~VK_DATA_IN_OFFSET));
	}

	/* copy subkeys into the struct regsubkey_ctr */

	key->subkey_index = 0;
	while ((subkey = regfio_fetch_subkey( regfile, key ))) {
		result = regsubkey_ctr_addkey(subkeys, subkey->keyname);
		if (!W_ERROR_IS_OK(result)) {
			TALLOC_FREE(subkeys);
			return result;
		}
	}

	/* write this key and values out */

	if (!store_reg_values(&registry_key, values)
	    || !store_reg_keys(&registry_key, subkeys))
	{
		DEBUG(0,("reg_load_tree: Failed to load %s!\n", topkeypath));
		result = WERR_REG_IO_FAILURE;
	}

	TALLOC_FREE(subkeys);

	if (!W_ERROR_IS_OK(result)) {
		return result;
	}

	/* now continue to load each subkey registry tree */

	key->subkey_index = 0;
	while ((subkey = regfio_fetch_subkey(regfile, key))) {
		path = talloc_asprintf(regfile->mem_ctx,
				       "%s\\%s",
				       topkeypath,
				       subkey->keyname);
		if (path == NULL) {
			return WERR_NOMEM;
		}
		result = reg_load_tree(regfile, path, subkey);
		if (!W_ERROR_IS_OK(result)) {
			break;
		}
	}

	return result;
}