static uint32_t _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb, int keyval, char **retbuf, uint32_t buffer_size) { TDB_DATA kbuf, dbuf; char temp[PERFCOUNT_MAX_LEN] = {0}; char *buf1 = *retbuf; uint32_t working_size = 0; DATA_BLOB name_index, name; bool ok; snprintf(temp, sizeof(temp), "%d", keyval); kbuf = string_tdb_data(temp); dbuf = tdb_fetch(tdb, kbuf); if(dbuf.dptr == NULL) { /* If a key isn't there, just bypass it -- this really shouldn't happen unless someone's mucking around with the tdb */ DEBUG(3, ("_reg_perfcount_multi_sz_from_tdb: failed to find key [%s] in [%s].\n", temp, tdb_name(tdb))); return buffer_size; } /* First encode the name_index */ working_size = (kbuf.dsize + 1)*sizeof(uint16_t); buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size); if(!buf1) { buffer_size = 0; return buffer_size; } ok = push_reg_sz(talloc_tos(), &name_index, (const char *)kbuf.dptr); if (!ok) { buffer_size = 0; return buffer_size; } memcpy(buf1+buffer_size, (char *)name_index.data, working_size); buffer_size += working_size; /* Now encode the actual name */ working_size = (dbuf.dsize + 1)*sizeof(uint16_t); buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size); if(!buf1) { buffer_size = 0; return buffer_size; } memset(temp, 0, sizeof(temp)); memcpy(temp, dbuf.dptr, dbuf.dsize); SAFE_FREE(dbuf.dptr); ok = push_reg_sz(talloc_tos(), &name, temp); if (!ok) { buffer_size = 0; return buffer_size; } memcpy(buf1+buffer_size, (char *)name.data, working_size); buffer_size += working_size; *retbuf = buf1; return buffer_size; }
WERROR nt_printer_guid_store(struct messaging_context *msg_ctx, const char *printer, struct GUID guid) { TALLOC_CTX *tmp_ctx; const struct auth_session_info *session_info; const char *guid_str; DATA_BLOB blob; WERROR result; tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { DEBUG(0, ("Out of memory?!\n")); return WERR_NOMEM; } session_info = get_session_info_system(); if (session_info == NULL) { DEBUG(0, ("Could not get system session_info\n")); result = WERR_NOMEM; goto done; } guid_str = GUID_string(tmp_ctx, &guid); if (!guid_str) { DEBUG(0, ("Out of memory?!\n")); result = WERR_NOMEM; goto done; } /* We used to store this as a REG_BINARY but that causes Vista to whine */ if (!push_reg_sz(tmp_ctx, &blob, guid_str)) { DEBUG(0, ("Could not marshall string %s for objectGUID\n", guid_str)); result = WERR_NOMEM; goto done; } result = winreg_set_printer_dataex_internal(tmp_ctx, session_info, msg_ctx, printer, SPOOL_DSSPOOLER_KEY, "objectGUID", REG_SZ, blob.data, blob.length); if (!W_ERROR_IS_OK(result)) { DEBUG(0, ("Failed to store GUID for printer %s\n", printer)); goto done; } result = WERR_OK; done: talloc_free(tmp_ctx); return result; }
static int net_registry_setvalue(struct net_context *c, int argc, const char **argv) { WERROR werr; struct registry_value value; struct registry_key *key = NULL; int ret = -1; TALLOC_CTX *ctx = talloc_stackframe(); if (argc < 4 || c->display_usage) { d_fprintf(stderr, "%s\n%s", _("Usage:"), _("net registry setvalue <key> <valuename> " "<type> [<val>]+\n")); goto done; } if (!strequal(argv[2], "multi_sz") && (argc != 4)) { d_fprintf(stderr, _("Too many args for type %s\n"), argv[2]); goto done; } if (strequal(argv[2], "dword")) { uint32_t v = strtoul(argv[3], NULL, 10); value.type = REG_DWORD; value.data = data_blob_talloc(ctx, NULL, 4); SIVAL(value.data.data, 0, v); } else if (strequal(argv[2], "sz")) { value.type = REG_SZ; if (!push_reg_sz(ctx, &value.data, argv[3])) { goto done; } } else if (strequal(argv[2], "multi_sz")) { const char **array; int count = argc - 3; int i; value.type = REG_MULTI_SZ; array = talloc_zero_array(ctx, const char *, count + 1); if (array == NULL) { goto done; } for (i=0; i < count; i++) { array[i] = talloc_strdup(array, argv[count+i]); if (array[i] == NULL) { goto done; } } if (!push_reg_multi_sz(ctx, &value.data, array)) { goto done; } } else {
static void store_printer_guid(struct messaging_context *msg_ctx, const char *printer, struct GUID guid) { TALLOC_CTX *tmp_ctx; struct auth_serversupplied_info *session_info = NULL; const char *guid_str; DATA_BLOB blob; NTSTATUS status; WERROR result; tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { DEBUG(0, ("store_printer_guid: Out of memory?!\n")); return; } status = make_session_info_system(tmp_ctx, &session_info); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("store_printer_guid: " "Could not create system session_info\n")); goto done; } guid_str = GUID_string(tmp_ctx, &guid); if (!guid_str) { DEBUG(0, ("store_printer_guid: Out of memory?!\n")); goto done; } /* We used to store this as a REG_BINARY but that causes Vista to whine */ if (!push_reg_sz(tmp_ctx, &blob, guid_str)) { DEBUG(0, ("store_printer_guid: " "Could not marshall string %s for objectGUID\n", guid_str)); goto done; } result = winreg_set_printer_dataex(tmp_ctx, session_info, msg_ctx, printer, SPOOL_DSSPOOLER_KEY, "objectGUID", REG_SZ, blob.data, blob.length); if (!W_ERROR_IS_OK(result)) { DEBUG(0, ("store_printer_guid: " "Failed to store GUID for printer %s\n", printer)); } done: talloc_free(tmp_ctx); }
WERROR gp_store_reg_val_sz(TALLOC_CTX *mem_ctx, struct registry_key *key, const char *val_name, const char *val) { struct registry_value reg_val; reg_val.type = REG_SZ; if (!push_reg_sz(mem_ctx, ®_val.data, val)) { return WERR_NOMEM; } return reg_setvalue(key, val_name, ®_val); }
struct registry_value *registry_value_sz(TALLOC_CTX *mem_ctx, const char *str) { struct registry_value *ret; ret = talloc_zero(mem_ctx, struct registry_value); if (ret == NULL) { return NULL; } if (!push_reg_sz(ret, &ret->data, str)) { talloc_free(ret); return NULL; } ret->type = REG_SZ; return ret; }
static NTSTATUS generate_gp_registry_entry(TALLOC_CTX *mem_ctx, const char *key, const char *value, uint32_t data_type, const void *data_p, enum gp_reg_action action, struct gp_registry_entry **entry_out) { struct gp_registry_entry *entry = NULL; struct registry_value *data = NULL; entry = talloc_zero(mem_ctx, struct gp_registry_entry); NT_STATUS_HAVE_NO_MEMORY(entry); data = talloc_zero(mem_ctx, struct registry_value); NT_STATUS_HAVE_NO_MEMORY(data); data->type = data_type; switch (data->type) { case REG_QWORD: data->data = data_blob_talloc(mem_ctx, NULL, 8); SBVAL(data->data.data, 0, *(uint64_t *)data_p); break; case REG_SZ: if (!push_reg_sz(mem_ctx, &data->data, (const char *)data_p)) { return NT_STATUS_NO_MEMORY; } break; default: return NT_STATUS_NOT_SUPPORTED; } entry->key = key; entry->data = data; entry->action = action; entry->value = talloc_strdup(mem_ctx, value); NT_STATUS_HAVE_NO_MEMORY(entry->value); *entry_out = entry; return NT_STATUS_OK; }
NTSTATUS dcerpc_winreg_set_expand_sz(TALLOC_CTX *mem_ctx, struct dcerpc_binding_handle *h, struct policy_handle *key_handle, const char *value, const char *data, WERROR *pwerr) { struct winreg_String wvalue = { 0, }; DATA_BLOB blob; WERROR result = WERR_OK; NTSTATUS status; wvalue.name = value; if (data == NULL) { blob = data_blob_string_const(""); } else { if (!push_reg_sz(mem_ctx, &blob, data)) { DEBUG(2, ("dcerpc_winreg_set_expand_sz: Could not marshall " "string %s for %s\n", data, wvalue.name)); *pwerr = WERR_NOMEM; return NT_STATUS_OK; } } status = dcerpc_winreg_SetValue(h, mem_ctx, key_handle, wvalue, REG_EXPAND_SZ, blob.data, blob.length, &result); if (!NT_STATUS_IS_OK(status)) { return status; } if (!W_ERROR_IS_OK(result)) { *pwerr = result; } return status; }
WERROR _PNP_GetDeviceRegProp(struct pipes_struct *p, struct PNP_GetDeviceRegProp *r) { char *ptr; const char *result; DATA_BLOB blob; TALLOC_CTX *mem_ctx = NULL; switch( r->in.property ) { case DEV_REGPROP_DESC: /* just parse the service name from the device path and then lookup the display name */ if ( !(ptr = strrchr_m( r->in.devicepath, '\\' )) ) return WERR_GEN_FAILURE; *ptr = '\0'; if ( !(ptr = strrchr_m( r->in.devicepath, '_' )) ) return WERR_GEN_FAILURE; ptr++; mem_ctx = talloc_stackframe(); result = svcctl_lookup_dispname(mem_ctx, p->msg_ctx, p->session_info, ptr); if (result == NULL) { return WERR_GEN_FAILURE; } if (!push_reg_sz(mem_ctx, &blob, result)) { talloc_free(mem_ctx); return WERR_GEN_FAILURE; } if (*r->in.buffer_size < blob.length) { *r->out.needed = blob.length; *r->out.buffer_size = 0; talloc_free(mem_ctx); return WERR_CM_BUFFER_SMALL; } r->out.buffer = (uint8_t *)talloc_memdup(p->mem_ctx, blob.data, blob.length); talloc_free(mem_ctx); if (!r->out.buffer) { return WERR_NOT_ENOUGH_MEMORY; } *r->out.reg_data_type = REG_SZ; /* always 1...tested using a remove device manager connection */ *r->out.buffer_size = blob.length; *r->out.needed = blob.length; break; default: *r->out.reg_data_type = 0x00437c98; /* ??? */ return WERR_CM_NO_SUCH_VALUE; } return WERR_OK; }
/** * add a value to a key. */ static sbcErr smbconf_reg_set_value(struct registry_key *key, const char *valname, const char *valstr) { struct registry_value val; WERROR werr = WERR_OK; sbcErr err; char *subkeyname; const char *canon_valname; const char *canon_valstr; if (!lp_canonicalize_parameter_with_value(valname, valstr, &canon_valname, &canon_valstr)) { if (canon_valname == NULL) { DEBUG(5, ("invalid parameter '%s' given\n", valname)); } else { DEBUG(5, ("invalid value '%s' given for " "parameter '%s'\n", valstr, valname)); } err = SBC_ERR_INVALID_PARAM; goto done; } if (smbconf_reg_valname_forbidden(canon_valname)) { DEBUG(5, ("Parameter '%s' not allowed in registry.\n", canon_valname)); err = SBC_ERR_INVALID_PARAM; goto done; } subkeyname = strrchr_m(key->key->name, '\\'); if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) { DEBUG(5, ("Invalid registry key '%s' given as " "smbconf section.\n", key->key->name)); err = SBC_ERR_INVALID_PARAM; goto done; } subkeyname++; if (!strequal(subkeyname, GLOBAL_NAME) && lp_parameter_is_global(valname)) { DEBUG(5, ("Global parameter '%s' not allowed in " "service definition ('%s').\n", canon_valname, subkeyname)); err = SBC_ERR_INVALID_PARAM; goto done; } ZERO_STRUCT(val); val.type = REG_SZ; if (!push_reg_sz(talloc_tos(), &val.data, canon_valstr)) { err = SBC_ERR_NOMEM; goto done; } werr = reg_setvalue(key, canon_valname, &val); if (!W_ERROR_IS_OK(werr)) { DEBUG(5, ("Error adding value '%s' to " "key '%s': %s\n", canon_valname, key->key->name, win_errstr(werr))); err = SBC_ERR_NOMEM; goto done; } err = SBC_ERR_OK; done: return err; }