*/
#include "includes.h"
-#include "../librpc/gen_ndr/cli_spoolss.h"
+#include "ads.h"
+#include "rpc_client/rpc_client.h"
+#include "../librpc/gen_ndr/ndr_spoolss_c.h"
+#include "rpc_client/cli_spoolss.h"
+#include "registry.h"
+#include "libcli/registry/util_reg.h"
#ifdef HAVE_ADS
return status;
}
if (ads_count_replies(ads, *res) != 1) {
- if (res) {
- ads_msgfree(ads, *res);
- *res = NULL;
- }
+ ads_msgfree(ads, *res);
+ *res = NULL;
return ADS_ERROR(LDAP_NO_SUCH_OBJECT);
}
srv_dn = ldap_get_dn(ads->ldap.ld, *res);
if (srv_dn == NULL) {
- if (res) {
- ads_msgfree(ads, *res);
- *res = NULL;
- }
+ ads_msgfree(ads, *res);
+ *res = NULL;
return ADS_ERROR(LDAP_NO_MEMORY);
}
srv_cn = ldap_explode_dn(srv_dn, 1);
if (srv_cn == NULL) {
ldap_memfree(srv_dn);
- if (res) {
- ads_msgfree(ads, *res);
- *res = NULL;
- }
- return ADS_ERROR(LDAP_INVALID_DN_SYNTAX);
- }
- if (res) {
ads_msgfree(ads, *res);
*res = NULL;
+ return ADS_ERROR(LDAP_INVALID_DN_SYNTAX);
}
+ ads_msgfree(ads, *res);
+ *res = NULL;
if (asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer) == -1) {
ldap_memfree(srv_dn);
/*
map a REG_SZ to an ldap mod
*/
-static bool map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
- const struct regval_blob *value)
+static bool map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
+ const char *name, struct registry_value *value)
{
- char *str_value = NULL;
- size_t converted_size;
+ const char *str_value = NULL;
ADS_STATUS status;
if (value->type != REG_SZ)
return false;
- if (value->size && *((smb_ucs2_t *) value->data_p)) {
- if (!pull_ucs2_talloc(ctx, &str_value,
- (const smb_ucs2_t *) value->data_p,
- &converted_size))
- {
+ if (value->data.length && value->data.data) {
+ if (!pull_reg_sz(ctx, &value->data, &str_value)) {
return false;
}
- status = ads_mod_str(ctx, mods, value->valuename, str_value);
+ status = ads_mod_str(ctx, mods, name, str_value);
return ADS_ERR_OK(status);
}
return true;
-
}
/*
map a REG_DWORD to an ldap mod
*/
-static bool map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods,
- const struct regval_blob *value)
+static bool map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods,
+ const char *name, struct registry_value *value)
{
char *str_value = NULL;
ADS_STATUS status;
- if (value->type != REG_DWORD)
- return False;
- str_value = talloc_asprintf(ctx, "%d", *((uint32 *) value->data_p));
+ if (value->type != REG_DWORD) {
+ return false;
+ }
+ if (value->data.length != sizeof(uint32_t)) {
+ return false;
+ }
+ str_value = talloc_asprintf(ctx, "%d", IVAL(value->data.data, 0));
if (!str_value) {
- return False;
+ return false;
}
- status = ads_mod_str(ctx, mods, value->valuename, str_value);
+ status = ads_mod_str(ctx, mods, name, str_value);
return ADS_ERR_OK(status);
}
map a boolean REG_BINARY to an ldap mod
*/
static bool map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods,
- const struct regval_blob *value)
+ const char *name, struct registry_value *value)
{
- char *str_value;
+ const char *str_value;
ADS_STATUS status;
- if ((value->type != REG_BINARY) || (value->size != 1))
- return False;
- str_value = talloc_asprintf(ctx, "%s",
- *(value->data_p) ? "TRUE" : "FALSE");
- if (!str_value) {
- return False;
+ if (value->type != REG_BINARY) {
+ return false;
+ }
+ if (value->data.length != 1) {
+ return false;
}
- status = ads_mod_str(ctx, mods, value->valuename, str_value);
+
+ str_value = *value->data.data ? "TRUE" : "FALSE";
+
+ status = ads_mod_str(ctx, mods, name, str_value);
return ADS_ERR_OK(status);
}
map a REG_MULTI_SZ to an ldap mod
*/
static bool map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
- const struct regval_blob *value)
+ const char *name, struct registry_value *value)
{
- char **str_values = NULL;
- size_t converted_size;
- smb_ucs2_t *cur_str = (smb_ucs2_t *) value->data_p;
- uint32 size = 0, num_vals = 0, i=0;
+ const char **str_values = NULL;
ADS_STATUS status;
- if (value->type != REG_MULTI_SZ)
- return False;
-
- while(cur_str && *cur_str && (size < value->size)) {
- size += 2 * (strlen_w(cur_str) + 1);
- cur_str += strlen_w(cur_str) + 1;
- num_vals++;
- };
+ if (value->type != REG_MULTI_SZ) {
+ return false;
+ }
- if (num_vals) {
- str_values = TALLOC_ARRAY(ctx, char *, num_vals + 1);
- if (!str_values) {
- return False;
- }
- memset(str_values, '\0',
- (num_vals + 1) * sizeof(char *));
-
- cur_str = (smb_ucs2_t *) value->data_p;
- for (i=0; i < num_vals; i++) {
- cur_str += pull_ucs2_talloc(ctx, &str_values[i],
- cur_str, &converted_size) ?
- converted_size : (size_t)-1;
+ if (value->data.length && value->data.data) {
+ if (!pull_reg_multi_sz(ctx, &value->data, &str_values)) {
+ return false;
}
-
- status = ads_mod_strlist(ctx, mods, value->valuename,
- (const char **) str_values);
+ status = ads_mod_strlist(ctx, mods, name, str_values);
return ADS_ERR_OK(status);
- }
- return True;
+ }
+ return true;
}
struct valmap_to_ads {
const char *valname;
- bool (*fn)(TALLOC_CTX *, ADS_MODLIST *, const struct regval_blob *);
+ bool (*fn)(TALLOC_CTX *, ADS_MODLIST *, const char *, struct registry_value *);
};
/*
map a REG_SZ to an ldap mod
*/
static void map_regval_to_ads(TALLOC_CTX *ctx, ADS_MODLIST *mods,
- struct regval_blob *value)
+ const char *name, struct registry_value *value)
{
const struct valmap_to_ads map[] = {
{SPOOL_REG_ASSETNUMBER, map_sz},
int i;
for (i=0; map[i].valname; i++) {
- if (StrCaseCmp(map[i].valname, value->valuename) == 0) {
- if (!map[i].fn(ctx, mods, value)) {
- DEBUG(5, ("Add of value %s to modlist failed\n", value->valuename));
+ if (strcasecmp_m(map[i].valname, name) == 0) {
+ if (!map[i].fn(ctx, mods, name, value)) {
+ DEBUG(5, ("Add of value %s to modlist failed\n", name));
} else {
- DEBUG(7, ("Mapped value %s\n", value->valuename));
+ DEBUG(7, ("Mapped value %s\n", name));
}
-
}
}
}
ADS_MODLIST *mods,
const char *printer)
{
+ struct dcerpc_binding_handle *b = cli->binding_handle;
WERROR result;
char *printername;
struct spoolss_PrinterEnumValues *info;
uint32_t count;
- uint32 i;
+ uint32_t i;
struct policy_handle pol;
+ WERROR werr;
if ((asprintf(&printername, "%s\\%s", cli->srv_name_slash, printer) == -1)) {
DEBUG(3, ("Insufficient memory\n"));
- return WERR_NOMEM;
+ return WERR_NOT_ENOUGH_MEMORY;
}
result = rpccli_spoolss_openprinter_ex(cli, mem_ctx,
} else {
/* Have the data we need now, so start building */
for (i=0; i < count; i++) {
- struct regval_blob v;
- DATA_BLOB blob;
-
- result = push_spoolss_PrinterData(mem_ctx, &blob,
- info[i].type,
- info[i].data);
- if (W_ERROR_IS_OK(result)) {
- fstrcpy(v.valuename, info[i].value_name);
- v.type = info[i].type;
- v.data_p = blob.data;
- v.size = blob.length;
-
- map_regval_to_ads(mem_ctx, mods, &v);
- }
+ struct registry_value v;
+ v.type = info[i].type;
+ v.data = *info[i].data;
+
+ map_regval_to_ads(mem_ctx, mods, info[i].value_name, &v);
}
}
printername, win_errstr(result)));
} else {
for (i=0; i < count; i++) {
- struct regval_blob v;
- DATA_BLOB blob = data_blob_null;
-
- result = push_spoolss_PrinterData(mem_ctx, &blob,
- info[i].type,
- info[i].data);
- if (W_ERROR_IS_OK(result)) {
- fstrcpy(v.valuename, info[i].value_name);
- v.type = info[i].type;
- v.data_p = blob.data;
- v.size = blob.length;
-
- map_regval_to_ads(mem_ctx, mods, &v);
- }
+ struct registry_value v;
+ v.type = info[i].type;
+ v.data = *info[i].data;
+
+ map_regval_to_ads(mem_ctx, mods, info[i].value_name, &v);
}
}
ads_mod_str(mem_ctx, mods, SPOOL_REG_PRINTERNAME, printer);
- rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
+ dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &werr);
SAFE_FREE(printername);
return result;
}
-bool get_local_printer_publishing_data(TALLOC_CTX *mem_ctx,
- ADS_MODLIST *mods,
- NT_PRINTER_DATA *data)
-{
- uint32 key,val;
-
- for (key=0; key < data->num_keys; key++) {
- struct regval_ctr *ctr = data->keys[key].values;
- for (val=0; val < ctr->num_values; val++)
- map_regval_to_ads(mem_ctx, mods, ctr->values[val]);
- }
- return True;
-}
-
#endif