*/
#include "includes.h"
+#include "../librpc/gen_ndr/cli_spoolss.h"
+#include "rpc_client/cli_spoolss.h"
+#include "registry.h"
+#include "registry/reg_objects.h"
+#include "nt_printing.h"
#ifdef HAVE_ADS
const char *servername)
{
ADS_STATUS status;
- char *srv_dn, **srv_cn, *s;
+ char *srv_dn, **srv_cn, *s = NULL;
const char *attrs[] = {"*", "nTSecurityDescriptor", NULL};
status = ads_find_machine_acct(ads, res, servername);
return status;
}
if (ads_count_replies(ads, *res) != 1) {
+ if (res) {
+ 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;
+ }
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);
}
- ads_msgfree(ads, *res);
+ if (res) {
+ ads_msgfree(ads, *res);
+ *res = NULL;
+ }
- asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer);
+ if (asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer) == -1) {
+ ldap_memfree(srv_dn);
+ return ADS_ERROR(LDAP_NO_MEMORY);
+ }
status = ads_search(ads, res, s, attrs);
ldap_memfree(srv_dn);
ldap_value_free(srv_cn);
- free(s);
+ SAFE_FREE(s);
return status;
}
map a REG_SZ to an ldap mod
*/
static bool map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
- const REGISTRY_VALUE *value)
+ struct regval_blob *value)
{
char *str_value = NULL;
+ size_t converted_size;
ADS_STATUS status;
- if (value->type != REG_SZ)
- return False;
+ if (regval_type(value) != REG_SZ)
+ return false;
- if (value->size && *((smb_ucs2_t *) value->data_p)) {
- pull_ucs2_talloc(ctx, &str_value, (const smb_ucs2_t *) value->data_p);
- status = ads_mod_str(ctx, mods, value->valuename, str_value);
+ if (regval_size(value) && *((smb_ucs2_t *) regval_data_p(value))) {
+ if (!pull_ucs2_talloc(ctx, &str_value,
+ (const smb_ucs2_t *) regval_data_p(value),
+ &converted_size))
+ {
+ return false;
+ }
+ status = ads_mod_str(ctx, mods, regval_name(value), str_value);
return ADS_ERR_OK(status);
}
- return True;
+ return true;
}
map a REG_DWORD to an ldap mod
*/
static bool map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods,
- const REGISTRY_VALUE *value)
+ struct regval_blob *value)
{
char *str_value = NULL;
ADS_STATUS status;
- if (value->type != REG_DWORD)
+ if (regval_type(value) != REG_DWORD)
return False;
- str_value = talloc_asprintf(ctx, "%d", *((uint32 *) value->data_p));
+ str_value = talloc_asprintf(ctx, "%d", *((uint32 *) regval_data_p(value)));
if (!str_value) {
return False;
}
- status = ads_mod_str(ctx, mods, value->valuename, str_value);
+ status = ads_mod_str(ctx, mods, regval_name(value), 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 REGISTRY_VALUE *value)
+ struct regval_blob *value)
{
char *str_value;
ADS_STATUS status;
- if ((value->type != REG_BINARY) || (value->size != 1))
+ if ((regval_type(value) != REG_BINARY) || (regval_size(value) != 1))
return False;
str_value = talloc_asprintf(ctx, "%s",
- *(value->data_p) ? "TRUE" : "FALSE");
+ *(regval_data_p(value)) ? "TRUE" : "FALSE");
if (!str_value) {
return False;
}
- status = ads_mod_str(ctx, mods, value->valuename, str_value);
+ status = ads_mod_str(ctx, mods, regval_name(value), 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 REGISTRY_VALUE *value)
+ struct regval_blob *value)
{
char **str_values = NULL;
- smb_ucs2_t *cur_str = (smb_ucs2_t *) value->data_p;
+ size_t converted_size;
+ smb_ucs2_t *cur_str = (smb_ucs2_t *) regval_data_p(value);
uint32 size = 0, num_vals = 0, i=0;
ADS_STATUS status;
- if (value->type != REG_MULTI_SZ)
+ if (regval_type(value) != REG_MULTI_SZ)
return False;
- while(cur_str && *cur_str && (size < value->size)) {
+ while(cur_str && *cur_str && (size < regval_size(value))) {
size += 2 * (strlen_w(cur_str) + 1);
cur_str += strlen_w(cur_str) + 1;
num_vals++;
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 = (smb_ucs2_t *) regval_data_p(value);
+ for (i=0; i < num_vals; i++) {
cur_str += pull_ucs2_talloc(ctx, &str_values[i],
- cur_str);
+ cur_str, &converted_size) ?
+ converted_size : (size_t)-1;
+ }
- status = ads_mod_strlist(ctx, mods, value->valuename,
+ status = ads_mod_strlist(ctx, mods, regval_name(value),
(const char **) str_values);
return ADS_ERR_OK(status);
}
struct valmap_to_ads {
const char *valname;
- bool (*fn)(TALLOC_CTX *, ADS_MODLIST *, const REGISTRY_VALUE *);
+ bool (*fn)(TALLOC_CTX *, ADS_MODLIST *, struct regval_blob *);
};
/*
map a REG_SZ to an ldap mod
*/
static void map_regval_to_ads(TALLOC_CTX *ctx, ADS_MODLIST *mods,
- REGISTRY_VALUE *value)
+ struct regval_blob *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 (StrCaseCmp(map[i].valname, regval_name(value)) == 0) {
if (!map[i].fn(ctx, mods, value)) {
- DEBUG(5, ("Add of value %s to modlist failed\n", value->valuename));
+ DEBUG(5, ("Add of value %s to modlist failed\n", regval_name(value)));
} else {
- DEBUG(7, ("Mapped value %s\n", value->valuename));
+ DEBUG(7, ("Mapped value %s\n", regval_name(value)));
}
}
const char *printer)
{
WERROR result;
- char *printername, *servername;
- REGVAL_CTR *dsdriver_ctr, *dsspooler_ctr;
+ char *printername;
+ struct spoolss_PrinterEnumValues *info;
+ uint32_t count;
uint32 i;
- POLICY_HND pol;
+ struct policy_handle pol;
- if ((asprintf(&servername, "\\\\%s", cli->desthost) == -1)
- || (asprintf(&printername, "%s\\%s", servername, printer) == -1)) {
+ if ((asprintf(&printername, "%s\\%s", cli->srv_name_slash, printer) == -1)) {
DEBUG(3, ("Insufficient memory\n"));
return WERR_NOMEM;
}
-
- result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername,
- "", MAXIMUM_ALLOWED_ACCESS,
- servername, cli->user_name, &pol);
+
+ result = rpccli_spoolss_openprinter_ex(cli, mem_ctx,
+ printername,
+ SEC_FLAG_MAXIMUM_ALLOWED,
+ &pol);
if (!W_ERROR_IS_OK(result)) {
DEBUG(3, ("Unable to open printer %s, error is %s.\n",
- printername, dos_errstr(result)));
+ printername, win_errstr(result)));
+ SAFE_FREE(printername);
return result;
}
-
- if ( !(dsdriver_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) )
- return WERR_NOMEM;
- result = rpccli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, dsdriver_ctr);
+ result = rpccli_spoolss_enumprinterdataex(cli, mem_ctx, &pol,
+ SPOOL_DSDRIVER_KEY,
+ 0,
+ &count,
+ &info);
if (!W_ERROR_IS_OK(result)) {
DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n",
- printername, dos_errstr(result)));
+ printername, win_errstr(result)));
} else {
- uint32 num_values = regval_ctr_numvals( dsdriver_ctr );
-
/* Have the data we need now, so start building */
- for (i=0; i < num_values; i++) {
- map_regval_to_ads(mem_ctx, mods, dsdriver_ctr->values[i]);
+ for (i=0; i < count; i++) {
+ struct regval_blob *v;
+
+ v = regval_compose(mem_ctx, info[i].value_name,
+ info[i].type,
+ info[i].data->data,
+ info[i].data->length);
+ if (v == NULL) {
+ return WERR_NOMEM;
+ }
+
+ map_regval_to_ads(mem_ctx, mods, v);
+ talloc_free(v);
}
}
-
- if ( !(dsspooler_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) )
- return WERR_NOMEM;
-
- result = rpccli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, dsspooler_ctr);
+ result = rpccli_spoolss_enumprinterdataex(cli, mem_ctx, &pol,
+ SPOOL_DSSPOOLER_KEY,
+ 0,
+ &count,
+ &info);
if (!W_ERROR_IS_OK(result)) {
DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n",
- printername, dos_errstr(result)));
+ printername, win_errstr(result)));
} else {
- uint32 num_values = regval_ctr_numvals( dsspooler_ctr );
+ for (i=0; i < count; i++) {
+ struct regval_blob *v;
+
+ v = regval_compose(mem_ctx, info[i].value_name,
+ info[i].type,
+ info[i].data->data,
+ info[i].data->length);
+ if (v == NULL) {
+ return WERR_NOMEM;
+ }
- for (i=0; i<num_values; i++) {
- map_regval_to_ads(mem_ctx, mods, dsspooler_ctr->values[i]);
+ map_regval_to_ads(mem_ctx, mods, v);
+ talloc_free(v);
}
}
-
- ads_mod_str(mem_ctx, mods, SPOOL_REG_PRINTERNAME, printer);
- TALLOC_FREE( dsdriver_ctr );
- TALLOC_FREE( dsspooler_ctr );
+ ads_mod_str(mem_ctx, mods, SPOOL_REG_PRINTERNAME, printer);
- rpccli_spoolss_close_printer(cli, mem_ctx, &pol);
+ rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
+ 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++) {
- 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