diff options
author | Günther Deschner <gd@samba.org> | 2009-09-24 15:01:32 +0200 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2009-09-30 00:30:12 +0200 |
commit | 1b0f3b7e3a3eadb1c9997b38dd41aa4c09c41a46 (patch) | |
tree | 0a0286fc31ccba857497fae5131e6b7561c69f9a | |
parent | a50cc61ee6bc973f913a8c26a082ae99f63091db (diff) | |
download | samba-1b0f3b7e3a3eadb1c9997b38dd41aa4c09c41a46.tar.gz samba-1b0f3b7e3a3eadb1c9997b38dd41aa4c09c41a46.tar.bz2 samba-1b0f3b7e3a3eadb1c9997b38dd41aa4c09c41a46.zip |
s3-registry: use regval_ctr_addvalue_sz().
Greatly simplifies and cleanes up the code.
Guenther
-rw-r--r-- | source3/printing/nt_printing.c | 28 | ||||
-rw-r--r-- | source3/registry/reg_backend_current_version.c | 12 | ||||
-rw-r--r-- | source3/registry/reg_backend_db.c | 8 | ||||
-rw-r--r-- | source3/registry/reg_backend_printing.c | 60 | ||||
-rw-r--r-- | source3/registry/reg_backend_prod_options.c | 7 | ||||
-rw-r--r-- | source3/registry/reg_backend_tcpip_params.c | 19 | ||||
-rw-r--r-- | source3/registry/reg_eventlog.c | 12 | ||||
-rw-r--r-- | source3/services/services_db.c | 46 |
8 files changed, 50 insertions, 142 deletions
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index f7591c19f5..f09615c06c 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -3033,14 +3033,8 @@ done: static void map_sz_into_ctr(struct regval_ctr *ctr, const char *val_name, const char *sz) { - smb_ucs2_t conv_str[1024]; - size_t str_size; - regval_ctr_delvalue(ctr, val_name); - str_size = push_ucs2(NULL, conv_str, sz, sizeof(conv_str), - STR_TERMINATE | STR_NOALIGN); - regval_ctr_addvalue(ctr, val_name, REG_SZ, - (char *) conv_str, str_size); + regval_ctr_addvalue_sz(ctr, val_name, sz); } static void map_dword_into_ctr(struct regval_ctr *ctr, const char *val_name, @@ -3167,7 +3161,6 @@ static void store_printer_guid(NT_PRINTER_INFO_LEVEL_2 *info2, { int i; struct regval_ctr *ctr=NULL; - DATA_BLOB unistr_guid; /* find the DsSpooler key */ if ((i = lookup_printerkey(info2->data, SPOOL_DSSPOOLER_KEY)) < 0) @@ -3179,12 +3172,8 @@ static void store_printer_guid(NT_PRINTER_INFO_LEVEL_2 *info2, /* We used to store this as a REG_BINARY but that causes Vista to whine */ - push_reg_sz(talloc_tos(), &unistr_guid, GUID_string(talloc_tos(), &guid)); - - regval_ctr_addvalue(ctr, "objectGUID", REG_SZ, - (char *)unistr_guid.data, - unistr_guid.length); - + regval_ctr_addvalue_sz(ctr, "objectGUID", + GUID_string(talloc_tos(), &guid)); } static WERROR nt_printer_publish_ads(ADS_STRUCT *ads, @@ -3781,19 +3770,14 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, const uint8 *buf, int bu strequal( valuename, "objectGUID" ) ) { struct GUID guid; - DATA_BLOB unistr_guid; /* convert the GUID to a UNICODE string */ memcpy( &guid, data_p, sizeof(struct GUID) ); - push_reg_sz(&talloc_tos, &unistr_guid, - GUID_string(talloc_tos(), &guid)); - - regval_ctr_addvalue( printer_data->keys[key_index].values, - valuename, REG_SZ, - (const char *)unistr_guid.data, - unistr_guid.length); + regval_ctr_addvalue_sz(printer_data->keys[key_index].values, + valuename, + GUID_string(talloc_tos(), &guid)); } else { /* add the value */ diff --git a/source3/registry/reg_backend_current_version.c b/source3/registry/reg_backend_current_version.c index 1a3b2819a6..386c580965 100644 --- a/source3/registry/reg_backend_current_version.c +++ b/source3/registry/reg_backend_current_version.c @@ -37,8 +37,6 @@ static int current_version_fetch_values(const char *key, struct regval_ctr *valu { const char *sysroot_string = "c:\\Windows"; fstring sysversion; - fstring value; - uint32 value_length; char *path = NULL; TALLOC_CTX *ctx = talloc_tos(); @@ -55,16 +53,12 @@ static int current_version_fetch_values(const char *key, struct regval_ctr *valu return regdb_ops.fetch_values(key, values); } - value_length = push_ucs2(value, value, sysroot_string, sizeof(value), - STR_TERMINATE|STR_NOALIGN ); - regval_ctr_addvalue(values, "SystemRoot", REG_SZ, value, value_length); + regval_ctr_addvalue_sz(values, "SystemRoot", sysroot_string); fstr_sprintf(sysversion, "%d.%d", lp_major_announce_version(), lp_minor_announce_version()); - value_length = push_ucs2(value, value, sysversion, sizeof(value), - STR_TERMINATE|STR_NOALIGN); - regval_ctr_addvalue(values, "CurrentVersion", REG_SZ, value, - value_length); + + regval_ctr_addvalue_sz(values, "CurrentVersion", sysversion); return regval_ctr_numvals(values); } diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c index b9ff5dc7fc..2b6259c03a 100644 --- a/source3/registry/reg_backend_db.c +++ b/source3/registry/reg_backend_db.c @@ -250,8 +250,6 @@ WERROR init_registry_key(const char *add_path) static void regdb_ctr_add_value(struct regval_ctr *ctr, struct builtin_regkey_value *value) { - DATA_BLOB data; - switch(value->type) { case REG_DWORD: regval_ctr_addvalue(ctr, value->valuename, REG_DWORD, @@ -260,10 +258,8 @@ static void regdb_ctr_add_value(struct regval_ctr *ctr, break; case REG_SZ: - push_reg_sz(talloc_tos(), &data, value->data.string); - regval_ctr_addvalue(ctr, value->valuename, REG_SZ, - (char*)data.data, - data.length); + regval_ctr_addvalue_sz(ctr, value->valuename, + value->data.string); break; default: diff --git a/source3/registry/reg_backend_printing.c b/source3/registry/reg_backend_printing.c index 2dc5d84215..cc44f877bb 100644 --- a/source3/registry/reg_backend_printing.c +++ b/source3/registry/reg_backend_printing.c @@ -386,7 +386,6 @@ static bool key_printers_store_keys( const char *key, struct regsubkey_ctr *subk static void fill_in_printer_values(NT_PRINTER_INFO_LEVEL_2 *info2, struct regval_ctr *values) { struct spoolss_DeviceMode *devmode; - DATA_BLOB data; char *p; uint32 printer_status = PRINTER_STATUS_OK; @@ -407,35 +406,16 @@ static void fill_in_printer_values(NT_PRINTER_INFO_LEVEL_2 *info2, struct regval else p++; - push_reg_sz(talloc_tos(), &data, p); - regval_ctr_addvalue( values, "Name", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, info2->location); - regval_ctr_addvalue( values, "Location", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, info2->comment); - regval_ctr_addvalue( values, "Description", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, info2->parameters); - regval_ctr_addvalue( values, "Parameters", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, info2->portname); - regval_ctr_addvalue( values, "Port", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, info2->sharename); - regval_ctr_addvalue( values, "Share Name", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, info2->drivername); - regval_ctr_addvalue( values, "Printer Driver", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, info2->sepfile); - regval_ctr_addvalue( values, "Separator File", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, "WinPrint"); - regval_ctr_addvalue( values, "Print Processor", REG_SZ, (char*)data.data, data.length); - - push_reg_sz(talloc_tos(), &data, "RAW"); - regval_ctr_addvalue( values, "Datatype", REG_SZ, (char*)data.data, data.length); + regval_ctr_addvalue_sz(values, "Name", p); + regval_ctr_addvalue_sz(values, "Location", info2->location); + regval_ctr_addvalue_sz(values, "Description", info2->comment); + regval_ctr_addvalue_sz(values, "Parameters", info2->parameters); + regval_ctr_addvalue_sz(values, "Port", info2->portname); + regval_ctr_addvalue_sz(values, "Share Name", info2->sharename); + regval_ctr_addvalue_sz(values, "Printer Driver", info2->drivername); + regval_ctr_addvalue_sz(values, "Separator File", info2->sepfile); + regval_ctr_addvalue_sz(values, "Print Processor", "WinPrint"); + regval_ctr_addvalue_sz(values, "Datatype", "RAW"); /* stream the device mode */ @@ -898,28 +878,18 @@ static void fill_in_driver_values(NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3, struct DATA_BLOB data; filename = dos_basename( info3->driverpath ); - push_reg_sz(talloc_tos(), &data, filename); - regval_ctr_addvalue( values, "Driver", REG_SZ, - (char *)data.data, data.length); + regval_ctr_addvalue_sz(values, "Driver", filename); filename = dos_basename( info3->configfile ); - push_reg_sz(talloc_tos(), &data, filename); - regval_ctr_addvalue( values, "Configuration File", REG_SZ, - (char *)data.data, data.length); + regval_ctr_addvalue_sz(values, "Configuration File", filename); filename = dos_basename( info3->datafile ); - push_reg_sz(talloc_tos(), &data, filename); - regval_ctr_addvalue( values, "Data File", REG_SZ, - (char *)data.data, data.length); + regval_ctr_addvalue_sz(values, "Data File", filename); filename = dos_basename( info3->helpfile ); - push_reg_sz(talloc_tos(), &data, filename); - regval_ctr_addvalue( values, "Help File", REG_SZ, - (char *)data.data, data.length); + regval_ctr_addvalue_sz(values, "Help File", filename); - push_reg_sz(talloc_tos(), &data, info3->defaultdatatype); - regval_ctr_addvalue( values, "Data Type", REG_SZ, - (char *)data.data, data.length); + regval_ctr_addvalue_sz(values, "Data Type", info3->defaultdatatype); regval_ctr_addvalue( values, "Version", REG_DWORD, (char*)&info3->cversion, sizeof(info3->cversion) ); diff --git a/source3/registry/reg_backend_prod_options.c b/source3/registry/reg_backend_prod_options.c index cdc1f37e72..786bc99eb1 100644 --- a/source3/registry/reg_backend_prod_options.c +++ b/source3/registry/reg_backend_prod_options.c @@ -34,8 +34,6 @@ extern struct registry_ops regdb_ops; static int prod_options_fetch_values(const char *key, struct regval_ctr *regvals) { const char *value_ascii = ""; - fstring value; - int value_length; switch (lp_server_role()) { case ROLE_DOMAIN_PDC: @@ -50,10 +48,7 @@ static int prod_options_fetch_values(const char *key, struct regval_ctr *regvals 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); + regval_ctr_addvalue_sz(regvals, "ProductType", value_ascii); return regval_ctr_numvals( regvals ); } diff --git a/source3/registry/reg_backend_tcpip_params.c b/source3/registry/reg_backend_tcpip_params.c index 30f7f71938..fbad0436b6 100644 --- a/source3/registry/reg_backend_tcpip_params.c +++ b/source3/registry/reg_backend_tcpip_params.c @@ -33,24 +33,9 @@ extern struct registry_ops regdb_ops; static int tcpip_params_fetch_values(const char *key, struct regval_ctr *regvals) { - fstring value; - int value_length; - char *hname; - char *mydomainname = NULL; + regval_ctr_addvalue_sz(regvals, "Hostname", myhostname()); - hname = myhostname(); - value_length = push_ucs2(value, value, hname, sizeof(value), - STR_TERMINATE|STR_NOALIGN); - regval_ctr_addvalue(regvals, "Hostname",REG_SZ, value, value_length); - - mydomainname = get_mydnsdomname(talloc_tos()); - if (!mydomainname) { - return -1; - } - - value_length = push_ucs2(value, value, mydomainname, sizeof(value), - STR_TERMINATE|STR_NOALIGN); - regval_ctr_addvalue(regvals, "Domain", REG_SZ, value, value_length); + regval_ctr_addvalue_sz(regvals, "Domain", get_mydnsdomname(talloc_tos())); return regval_ctr_numvals(regvals); } diff --git a/source3/registry/reg_eventlog.c b/source3/registry/reg_eventlog.c index c0d5b95b0b..4d395eddb1 100644 --- a/source3/registry/reg_eventlog.c +++ b/source3/registry/reg_eventlog.c @@ -114,11 +114,8 @@ bool eventlog_init_keys(void) regval_ctr_addvalue(values, "Retention", REG_DWORD, (char *)&uiRetention, sizeof(uint32)); - push_reg_sz(talloc_tos(), &data, *elogs); - regval_ctr_addvalue(values, "PrimaryModule", REG_SZ, - (char *)data.data, - data.length); + regval_ctr_addvalue_sz(values, "PrimaryModule", *elogs); push_reg_sz(talloc_tos(), &data, *elogs); regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ, @@ -199,7 +196,6 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename, struct regsubkey_ctr *subkeys; struct regval_ctr *values; struct regval_blob *rval; - DATA_BLOB data; uint16 *msz_wp; int mbytes, ii; bool already_in; @@ -369,11 +365,7 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename, regdb_fetch_values( evtlogpath, values ); - push_reg_sz(talloc_tos(), &data, messagefile); - - regval_ctr_addvalue( values, "EventMessageFile", REG_SZ, - ( char * ) data.data, - data.length); + regval_ctr_addvalue_sz(values, "EventMessageFile", messagefile); regdb_store_values( evtlogpath, values ); TALLOC_FREE(values); diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 1aeade8b98..b36774484d 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -250,7 +250,7 @@ static bool read_init_file( const char *servicename, struct rcinit_file_informat static void fill_service_values(const char *name, struct regval_ctr *values) { - DATA_BLOB data, dname, ipath, description; + char *dname, *ipath, *description; uint32 dword; int i; @@ -268,24 +268,17 @@ static void fill_service_values(const char *name, struct regval_ctr *values) /* everything runs as LocalSystem */ - push_reg_sz(talloc_tos(), &data, "LocalSystem"); - regval_ctr_addvalue( values, "ObjectName", REG_SZ, (char *)data.data, data.length); + regval_ctr_addvalue_sz(values, "ObjectName", "LocalSystem"); /* special considerations for internal services and the DisplayName value */ for ( i=0; builtin_svcs[i].servicename; i++ ) { if ( strequal( name, builtin_svcs[i].servicename ) ) { - char *pstr = NULL; - if (asprintf(&pstr, "%s/%s/%s", + ipath = talloc_asprintf(talloc_tos(), "%s/%s/%s", get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, - builtin_svcs[i].daemon) > 0) { - push_reg_sz(talloc_tos(), &ipath, pstr); - SAFE_FREE(pstr); - } else { - push_reg_sz(talloc_tos(), &ipath, ""); - } - push_reg_sz(talloc_tos(), &description, builtin_svcs[i].description); - push_reg_sz(talloc_tos(), &dname, builtin_svcs[i].dispname); + builtin_svcs[i].daemon); + description = talloc_strdup(talloc_tos(), builtin_svcs[i].description); + dname = talloc_strdup(talloc_tos(), builtin_svcs[i].dispname); break; } } @@ -293,38 +286,37 @@ static void fill_service_values(const char *name, struct regval_ctr *values) /* default to an external service if we haven't found a match */ if ( builtin_svcs[i].servicename == NULL ) { - char *pstr = NULL; char *dispname = NULL; struct rcinit_file_information *init_info = NULL; - if (asprintf(&pstr, "%s/%s/%s",get_dyn_MODULESDIR(), - SVCCTL_SCRIPT_DIR, name) > 0) { - push_reg_sz(talloc_tos(), &ipath, pstr); - SAFE_FREE(pstr); - } else { - push_reg_sz(talloc_tos(), &ipath, ""); - } + ipath = talloc_asprintf(talloc_tos(), "%s/%s/%s", + get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, + name); /* lookup common unix display names */ dispname = get_common_service_dispname(name); - push_reg_sz(talloc_tos(), &dname, dispname ? dispname : ""); + dname = talloc_strdup(talloc_tos(), dispname ? dispname : ""); SAFE_FREE(dispname); /* get info from init file itself */ if ( read_init_file( name, &init_info ) ) { - push_reg_sz(talloc_tos(), &description, init_info->description); + description = talloc_strdup(talloc_tos(), init_info->description); TALLOC_FREE( init_info ); } else { - push_reg_sz(talloc_tos(), &description, "External Unix Service"); + description = talloc_strdup(talloc_tos(), "External Unix Service"); } } /* add the new values */ - regval_ctr_addvalue( values, "DisplayName", REG_SZ, (char*)dname.data, dname.length); - regval_ctr_addvalue( values, "ImagePath", REG_SZ, (char*)ipath.data, ipath.length); - regval_ctr_addvalue( values, "Description", REG_SZ, (char*)description.data, description.length); + regval_ctr_addvalue_sz(values, "DisplayName", dname); + regval_ctr_addvalue_sz(values, "ImagePath", ipath); + regval_ctr_addvalue_sz(values, "Description", description); + + TALLOC_FREE(dname); + TALLOC_FREE(ipath); + TALLOC_FREE(description); return; } |