Beispiel #1
0
BOOL prs_werror(const char *name, prs_struct *ps, int depth, WERROR *status)
{
	char *q = prs_mem_get(ps, sizeof(uint32));
	if (q == NULL)
		return False;

	if (UNMARSHALLING(ps)) {
		if (ps->bigendian_data)
			*status = W_ERROR(RIVAL(q,0));
		else
			*status = W_ERROR(IVAL(q,0));
	} else {
		if (ps->bigendian_data)
			RSIVAL(q,0,W_ERROR_V(*status));
		else
			SIVAL(q,0,W_ERROR_V(*status));
	}

	DEBUG(5,("%s%04x %s: %s\n", tab_depth(depth), ps->data_offset, name, 
		 dos_errstr(*status)));

	ps->data_offset += sizeof(uint32);

	return True;
}
Beispiel #2
0
const char *get_friendly_werror_msg(WERROR werror)
{
    int i = 0;

    for (i = 0; i < ARRAY_SIZE(dos_err_strs); i++) {
        if (W_ERROR_V(dos_err_strs[i].werror) ==
                W_ERROR_V(werror)) {
            return dos_err_strs[i].friendly_errstr;
        }
    }

    return win_errstr(werror);
}
Beispiel #3
0
bool torture_libnetapi_init_context(struct torture_context *tctx,
				    struct libnetapi_ctx **ctx_p)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx;
	TALLOC_CTX *frame = talloc_stackframe();

	if (!lp_load_global(lpcfg_configfile(tctx->lp_ctx))) {
		fprintf(stderr, "error loading %s\n", lpcfg_configfile(tctx->lp_ctx));
		talloc_free(frame);
		return W_ERROR_V(WERR_GENERAL_FAILURE);
	}

	init_names();
	load_interfaces();

	status = libnetapi_net_init(&ctx);
	if (status != 0) {
		talloc_free(frame);
		return false;
	}

	libnetapi_set_username(ctx,
		cli_credentials_get_username(cmdline_credentials));
	libnetapi_set_password(ctx,
		cli_credentials_get_password(cmdline_credentials));

	*ctx_p = ctx;

	talloc_free(frame);
	return true;
}
Beispiel #4
0
const char *dos_errstr(WERROR werror)
{
        static pstring msg;
        int idx = 0;

	slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));

	while (dos_errs[idx].dos_errstr != NULL) {
		if (W_ERROR_V(dos_errs[idx].werror) == 
                    W_ERROR_V(werror))
                        return dos_errs[idx].dos_errstr;
		idx++;
	}

        return msg;
}
Beispiel #5
0
NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	char *krb5_cc_env = NULL;

	TALLOC_CTX *frame = talloc_stackframe();

	ctx = talloc_zero(frame, struct libnetapi_ctx);
	if (!ctx) {
		TALLOC_FREE(frame);
		return W_ERROR_V(WERR_NOMEM);
	}

	BlockSignals(True, SIGPIPE);

	krb5_cc_env = getenv(KRB5_ENV_CCNAME);
	if (!krb5_cc_env || (strlen(krb5_cc_env) == 0)) {
		ctx->krb5_cc_env = talloc_strdup(ctx, "MEMORY:libnetapi");
		setenv(KRB5_ENV_CCNAME, ctx->krb5_cc_env, 1);
	}

	if (getenv("USER")) {
		ctx->username = talloc_strdup(ctx, getenv("USER"));
	} else {
		ctx->username = talloc_strdup(ctx, "");
	}
	if (!ctx->username) {
		TALLOC_FREE(frame);
		fprintf(stderr, "libnetapi_init: out of memory\n");
		return W_ERROR_V(WERR_NOMEM);
	}

	status = libnetapi_init_private_context(ctx);
	if (status != 0) {
		TALLOC_FREE(frame);
		return status;
	}

	libnetapi_initialized = true;

	talloc_steal(NULL, ctx);
	*context = stat_ctx = ctx;
	
	TALLOC_FREE(frame);
	return NET_API_STATUS_SUCCESS;
}
Beispiel #6
0
static NET_API_STATUS libnetapi_init_private_context(struct libnetapi_ctx *ctx)
{
	struct libnetapi_private_ctx *priv;

	if (!ctx) {
		return W_ERROR_V(WERR_INVALID_PARAM);
	}

	priv = TALLOC_ZERO_P(ctx, struct libnetapi_private_ctx);
	if (!priv) {
		return W_ERROR_V(WERR_NOMEM);
	}

	ctx->private_data = priv;

	return NET_API_STATUS_SUCCESS;
}
Beispiel #7
0
const char *get_dos_error_msg(WERROR result)
{
	uint16 errnum;

	errnum = W_ERROR_V(result);

	return smb_dos_err_name(ERRDOS, errnum);
}
PyObject *spoolss_hnd_getprinter(PyObject *self, PyObject *args, PyObject *kw)
{
	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
	WERROR werror;
	PyObject *result = NULL;
	PRINTER_INFO_CTR ctr;
	int level = 1;
	uint32 needed;
	static char *kwlist[] = {"level", NULL};
	
	/* Parse parameters */

	if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level))
		return NULL;
	
	ZERO_STRUCT(ctr);

	/* Call rpc function */
	
	werror = cli_spoolss_getprinter(
		hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, &ctr);

	if (W_ERROR_V(werror) == ERRinsufficientbuffer)
		werror = cli_spoolss_getprinter(
			hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
			level, &ctr);

	/* Return value */

	if (!W_ERROR_IS_OK(werror)) {
		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
		return NULL;
	}

	result = Py_None;

	switch (level) {
		
	case 0:
		py_from_PRINTER_INFO_0(&result, ctr.printers_0);
		break;

	case 1:
		py_from_PRINTER_INFO_1(&result, ctr.printers_1);
		break;

	case 2:
		py_from_PRINTER_INFO_2(&result, ctr.printers_2);
		break;

	case 3:
		py_from_PRINTER_INFO_3(&result, ctr.printers_3);
		break;
	}

	Py_INCREF(result);
	return result;
}
PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args,
				   PyObject *kw)
{
	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
	WERROR werror;
	PyObject *result = Py_None;
	PRINTER_DRIVER_CTR ctr;
	int level = 1;
	uint32 needed;
	char *arch = "Windows NT x86";
	int version = 2;
	static char *kwlist[] = {"level", "arch", NULL};

	/* Parse parameters */

	if (!PyArg_ParseTupleAndKeywords(
		    args, kw, "|is", kwlist, &level, &arch))
		return NULL;

	/* Call rpc function */

	werror = cli_spoolss_getprinterdriver(
		hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
		version, arch, &ctr);

	if (W_ERROR_V(werror) == ERRinsufficientbuffer)
		werror = cli_spoolss_getprinterdriver(
			hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
			level, version, arch, &ctr);

	if (!W_ERROR_IS_OK(werror)) {
		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
		return NULL;
	}

	/* Return value */
	
	switch (level) {
	case 1:
		py_from_DRIVER_INFO_1(&result, ctr.info1);
		break;
	case 2: 
		py_from_DRIVER_INFO_2(&result, ctr.info2);
		break;
	case 3: 
		py_from_DRIVER_INFO_3(&result, ctr.info3);
		break;
	case 6:
		py_from_DRIVER_INFO_6(&result, ctr.info6);
		break;
	default:
		PyErr_SetString(spoolss_error, "unsupported info level");
		return NULL;
	}
	
	Py_INCREF(result);
	return result;
}
Beispiel #10
0
NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx,
				      const char *password)
{
	TALLOC_FREE(ctx->password);
	ctx->password = talloc_strdup(ctx, password);
	if (!ctx->password) {
		return W_ERROR_V(WERR_NOMEM);
	}
	return NET_API_STATUS_SUCCESS;
}
Beispiel #11
0
NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx,
				       const char *workgroup)
{
	TALLOC_FREE(ctx->workgroup);
	ctx->workgroup = talloc_strdup(ctx, workgroup);
	if (!ctx->workgroup) {
		return W_ERROR_V(WERR_NOMEM);
	}
	return NET_API_STATUS_SUCCESS;
}
Beispiel #12
0
NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
					const char *debuglevel)
{
	AllowDebugChange = true;
	ctx->debuglevel = talloc_strdup(ctx, debuglevel);
	if (!debug_parse_levels(debuglevel)) {
		return W_ERROR_V(WERR_GENERAL_FAILURE);
	}
	return NET_API_STATUS_SUCCESS;
}
Beispiel #13
0
NET_API_STATUS NetApiBufferFree(void *buffer)
{
	if (!buffer) {
		return W_ERROR_V(WERR_INSUFFICIENT_BUFFER);
	}

	talloc_free(buffer);

	return NET_API_STATUS_SUCCESS;
}
Beispiel #14
0
NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx,
				      const char *username)
{
	TALLOC_FREE(ctx->username);
	ctx->username = talloc_strdup(ctx, username ? username : "");

	if (!ctx->username) {
		return W_ERROR_V(WERR_NOMEM);
	}
	return NET_API_STATUS_SUCCESS;
}
Beispiel #15
0
NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
					const char *debuglevel)
{
	TALLOC_CTX *frame = talloc_stackframe();
	ctx->debuglevel = talloc_strdup(ctx, debuglevel);
	
	if (!lp_set_cmdline("log level", debuglevel)) {
		TALLOC_FREE(frame);
		return W_ERROR_V(WERR_GENERAL_FAILURE);
	}
	TALLOC_FREE(frame);
	return NET_API_STATUS_SUCCESS;
}
Beispiel #16
0
/*
  turn a WERROR into a MprVar object with lots of funky properties
*/
struct MprVar mprWERROR(WERROR status)
{
	struct MprVar res;

	res = mprObject("werror");

	mprSetVar(&res, "errstr", mprString(win_errstr(status)));
	mprSetVar(&res, "v", mprCreateIntegerVar(W_ERROR_V(status)));
	mprSetVar(&res, "is_ok", mprCreateBoolVar(W_ERROR_IS_OK(status)));
	mprSetVar(&res, "is_err", mprCreateBoolVar(!W_ERROR_IS_OK(status)));

	return res;
}
Beispiel #17
0
NET_API_STATUS NetApiBufferAllocate(uint32_t byte_count,
				    void **buffer)
{
	void *buf = NULL;

	if (!buffer) {
		return W_ERROR_V(WERR_INSUFFICIENT_BUFFER);
	}

	if (byte_count == 0) {
		goto done;
	}

	buf = talloc_size(NULL, byte_count);
	if (!buf) {
		return W_ERROR_V(WERR_NOMEM);
	}

 done:
	*buffer = buf;

	return NET_API_STATUS_SUCCESS;
}
Beispiel #18
0
NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx,
					  const char *format, ...)
{
	va_list args;

	TALLOC_FREE(ctx->error_string);

	va_start(args, format);
	ctx->error_string = talloc_vasprintf(ctx, format, args);
	va_end(args);

	if (!ctx->error_string) {
		return W_ERROR_V(WERR_NOMEM);
	}
	return NET_API_STATUS_SUCCESS;
}
Beispiel #19
0
_PUBLIC_ uint32_t dcerpc_fault_from_nt_status(NTSTATUS nt_status)
{
	int idx = 0;
	WERROR werr;

	if (NT_STATUS_IS_OK(nt_status)) {
		return DCERPC_NCA_S_PROTO_ERROR;
	}

	while (dcerpc_faults[idx].errstr != NULL) {
		if (NT_STATUS_EQUAL(dcerpc_faults[idx].nt_status, nt_status)) {
			return dcerpc_faults[idx].faultcode;
		}
		idx++;
	}

	werr = ntstatus_to_werror(nt_status);

	return W_ERROR_V(werr);
}
Beispiel #20
0
NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
{
	NET_API_STATUS ret;
	TALLOC_CTX *frame;
	if (stat_ctx && libnetapi_initialized) {
		*context = stat_ctx;
		return NET_API_STATUS_SUCCESS;
	}

#if 0
	talloc_enable_leak_report();
#endif
	frame = talloc_stackframe();

	/* Case tables must be loaded before any string comparisons occour */
	load_case_tables_library();

	/* When libnetapi is invoked from an application, it does not
	 * want to be swamped with level 10 debug messages, even if
	 * this has been set for the server in smb.conf */
	lp_set_cmdline("log level", "0");
	setup_logging("libnetapi", DEBUG_STDERR);

	if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, true)) {
		TALLOC_FREE(frame);
		fprintf(stderr, "error loading %s\n", get_dyn_CONFIGFILE() );
		return W_ERROR_V(WERR_GENERAL_FAILURE);
	}

	init_names();
	load_interfaces();
	reopen_logs();

	BlockSignals(True, SIGPIPE);

	ret = libnetapi_net_init(context);
	TALLOC_FREE(frame);
	return ret;
}
Beispiel #21
0
WERROR nt_printer_publish(TALLOC_CTX *mem_ctx,
			  const struct auth_serversupplied_info *session_info,
			  struct messaging_context *msg_ctx,
			  struct spoolss_PrinterInfo2 *pinfo2,
			  int action)
{
	uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ATTRIBUTES;
	struct spoolss_SetPrinterInfo2 *sinfo2;
	ADS_STATUS ads_rc;
	ADS_STRUCT *ads = NULL;
	WERROR win_rc;

	sinfo2 = talloc_zero(mem_ctx, struct spoolss_SetPrinterInfo2);
	if (!sinfo2) {
		return WERR_NOMEM;
	}

	switch (action) {
	case DSPRINT_PUBLISH:
	case DSPRINT_UPDATE:
		pinfo2->attributes |= PRINTER_ATTRIBUTE_PUBLISHED;
		break;
	case DSPRINT_UNPUBLISH:
		pinfo2->attributes ^= PRINTER_ATTRIBUTE_PUBLISHED;
		break;
	default:
		win_rc = WERR_NOT_SUPPORTED;
		goto done;
	}

	sinfo2->attributes = pinfo2->attributes;

	win_rc = winreg_update_printer(mem_ctx, session_info, msg_ctx,
					pinfo2->sharename, info2_mask,
					sinfo2, NULL, NULL);
	if (!W_ERROR_IS_OK(win_rc)) {
		DEBUG(3, ("err %d saving data\n", W_ERROR_V(win_rc)));
		goto done;
	}

	TALLOC_FREE(sinfo2);

	ads = ads_init(lp_realm(), lp_workgroup(), NULL);
	if (!ads) {
		DEBUG(3, ("ads_init() failed\n"));
		win_rc = WERR_SERVER_UNAVAILABLE;
		goto done;
	}
	setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1);
	SAFE_FREE(ads->auth.password);
	ads->auth.password = secrets_fetch_machine_password(lp_workgroup(),
		NULL, NULL);

	/* ads_connect() will find the DC for us */
	ads_rc = ads_connect(ads);
	if (!ADS_ERR_OK(ads_rc)) {
		DEBUG(3, ("ads_connect failed: %s\n", ads_errstr(ads_rc)));
		win_rc = WERR_ACCESS_DENIED;
		goto done;
	}

	switch (action) {
	case DSPRINT_PUBLISH:
	case DSPRINT_UPDATE:
		win_rc = nt_printer_publish_ads(msg_ctx, ads, pinfo2);
		break;
	case DSPRINT_UNPUBLISH:
		win_rc = nt_printer_unpublish_ads(ads, pinfo2->sharename);
		break;
	}

done:
	ads_destroy(&ads);
	return win_rc;
}
PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args,
				     PyObject *kw)
{
	WERROR werror;
	PyObject *result = NULL, *creds = NULL;
	PRINTER_DRIVER_CTR ctr;
	int level = 1, i;
	uint32 needed, num_drivers;
	char *arch = "Windows NT x86", *server, *errstr;
	static char *kwlist[] = {"server", "level", "creds", "arch", NULL};
	struct cli_state *cli = NULL;
	TALLOC_CTX *mem_ctx = NULL;
	
	/* Parse parameters */

	if (!PyArg_ParseTupleAndKeywords(
		    args, kw, "s|iOs", kwlist, &server, &level, &creds,
		    &arch)) 
		return NULL;
	
	if (server[0] != '\\' || server[1] != '\\') {
		PyErr_SetString(PyExc_ValueError, "UNC name required");
		return NULL;
	}

	server += 2;

	if (creds && creds != Py_None && !PyDict_Check(creds)) {
		PyErr_SetString(PyExc_TypeError, 
				"credentials must be dictionary or None");
		return NULL;
	}

	/* Call rpc function */
	
	if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
		PyErr_SetString(spoolss_error, errstr);
		free(errstr);
		goto done;
	}

	if (!(mem_ctx = talloc_init("spoolss_enumprinterdrivers"))) {
		PyErr_SetString(
			spoolss_error, "unable to init talloc context\n");
		goto done;
	}	

	werror = cli_spoolss_enumprinterdrivers(
		cli, mem_ctx, 0, &needed, level, arch,
		&num_drivers, &ctr);

	if (W_ERROR_V(werror) == ERRinsufficientbuffer)
		werror = cli_spoolss_enumprinterdrivers(
			cli, mem_ctx, needed, NULL, level, arch, 
			&num_drivers, &ctr);

	if (!W_ERROR_IS_OK(werror)) {
		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
		goto done;
	}

	/* Return value */

	switch (level) {
	case 1:
		result = PyDict_New();
		
		for (i = 0; i < num_drivers; i++) {
			PyObject *value;
			fstring name;
			
			rpcstr_pull(name, ctr.info1[i].name.buffer,
				    sizeof(fstring), -1, STR_TERMINATE);

			py_from_DRIVER_INFO_1(&value, &ctr.info1[i]);

			PyDict_SetItemString(result, name, value);
		}
		
		break;
	case 2: 
		result = PyDict_New();

		for(i = 0; i < num_drivers; i++) {
			PyObject *value;
			fstring name;

			rpcstr_pull(name, ctr.info2[i].name.buffer,
				    sizeof(fstring), -1, STR_TERMINATE);

			py_from_DRIVER_INFO_2(&value, &ctr.info2[i]);

			PyDict_SetItemString(result, name, value);
		}

		break;
	case 3: 
		result = PyDict_New();

		for(i = 0; i < num_drivers; i++) {
			PyObject *value;
			fstring name;

			rpcstr_pull(name, ctr.info3[i].name.buffer,
				    sizeof(fstring), -1, STR_TERMINATE);

			py_from_DRIVER_INFO_3(&value, &ctr.info3[i]);

			PyDict_SetItemString(result, name, value);
		}

		break;
	case 6: 
		result = PyDict_New();

		for(i = 0; i < num_drivers; i++) {
			PyObject *value;
			fstring name;

			rpcstr_pull(name, ctr.info6[i].name.buffer,
				    sizeof(fstring), -1, STR_TERMINATE);

			py_from_DRIVER_INFO_6(&value, &ctr.info6[i]);

			PyList_SetItem(result, i, value);
		}

		break;
	default:
		PyErr_SetString(spoolss_error, "unknown info level");
		goto done;
	}
	
 done:
	if (cli)
		cli_shutdown(cli);

	if (mem_ctx)
		talloc_destroy(mem_ctx);

	return result;
}
PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, 
				      PyObject *kw)
{
	WERROR werror;
	PyObject *result = NULL, *creds = NULL;
	DRIVER_DIRECTORY_CTR ctr;
	uint32 needed, level = 1;
	char *arch = "Windows NT x86", *server, *errstr;
	static char *kwlist[] = {"server", "level", "arch", "creds", NULL};
	struct cli_state *cli = NULL;
	TALLOC_CTX *mem_ctx = NULL;

	/* Parse parameters */

	if (!PyArg_ParseTupleAndKeywords(
		    args, kw, "s|isO", kwlist, &server, &level,
		    &arch, &creds))
		return NULL;

	if (server[0] != '\\' || server[1] != '\\') {
		PyErr_SetString(PyExc_ValueError, "UNC name required");
		return NULL;
	}

	server += 2;

	if (creds && creds != Py_None && !PyDict_Check(creds)) {
		PyErr_SetString(PyExc_TypeError, 
				"credentials must be dictionary or None");
		return NULL;
	}

	/* Call rpc function */

	if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
		PyErr_SetString(spoolss_error, errstr);
		free(errstr);
		goto done;
	}
	
	if (!(mem_ctx = talloc_init("spoolss_getprinterdriverdir"))) {
		PyErr_SetString(
			spoolss_error, "unable to init talloc context\n");
		goto done;
	}	

	werror = cli_spoolss_getprinterdriverdir(
		cli, mem_ctx, 0, &needed, level, arch, &ctr);

	if (W_ERROR_V(werror) == ERRinsufficientbuffer)
		werror = cli_spoolss_getprinterdriverdir(
			cli, mem_ctx, needed, NULL, level, arch, &ctr);

	if (!W_ERROR_IS_OK(werror)) {
		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
		goto done;
	}

	/* Return value */
	
	switch (level) {
	case 1:
		py_from_DRIVER_DIRECTORY_1(&result, ctr.info1);
		break;
	default:
		PyErr_SetString(spoolss_error, "unknown info level");
		goto done;	
	}
	
 done:
	if (cli)
		cli_shutdown(cli);
	
	if (mem_ctx)
		talloc_destroy(mem_ctx);

	return result;
}
PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw)
{
	WERROR werror;
	PyObject *result = NULL, *creds = NULL;
	PRINTER_INFO_CTR ctr;
	int level = 1, flags = PRINTER_ENUM_LOCAL, i;
	uint32 needed, num_printers;
	static char *kwlist[] = {"server", "name", "level", "flags", 
				 "creds", NULL};
	TALLOC_CTX *mem_ctx = NULL;
	struct cli_state *cli = NULL;
	char *server, *errstr, *name = NULL;

	/* Parse parameters */

	if (!PyArg_ParseTupleAndKeywords(
		    args, kw, "s|siiO", kwlist, &server, &name, &level, 
		    &flags, &creds))
		return NULL;
	
	if (server[0] != '\\' || server[1] != '\\') {
		PyErr_SetString(PyExc_ValueError, "UNC name required");
		return NULL;
	}

	server += 2;

	if (creds && creds != Py_None && !PyDict_Check(creds)) {
		PyErr_SetString(PyExc_TypeError, 
				"credentials must be dictionary or None");
		return NULL;
	}

	if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
		PyErr_SetString(spoolss_error, errstr);
		free(errstr);
		goto done;
	}

	if (!(mem_ctx = talloc_init("spoolss_enumprinters"))) {
		PyErr_SetString(
			spoolss_error, "unable to init talloc context\n");
		goto done;
	}

	/* This RPC is weird.  By setting the server name to different
	   values we can get different behaviour.  If however the server
	   name is not specified, we default it to being the full server
	   name as this is probably what the caller intended.  To pass a
	   NULL name, pass a value of "" */

	if (!name)
		name = server;
	else {
		if (!name[0])
			name = NULL;
	}

	/* Call rpc function */
	
	werror = cli_spoolss_enum_printers(
		cli, mem_ctx, 0, &needed, name, flags, level,
		&num_printers, &ctr);

	if (W_ERROR_V(werror) == ERRinsufficientbuffer)
		werror = cli_spoolss_enum_printers(
			cli, mem_ctx, needed, NULL, name, flags, 
			level, &num_printers, &ctr);

	if (!W_ERROR_IS_OK(werror)) {
		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
		goto done;
	}

	/* Return value */
	
	switch (level) {
	case 0: 
		result = PyDict_New();

		for (i = 0; i < num_printers; i++) {
			PyObject *value;
			fstring s;

			rpcstr_pull(s, ctr.printers_0[i].printername.buffer,
				    sizeof(fstring), -1, STR_TERMINATE);

			py_from_PRINTER_INFO_0(&value, &ctr.printers_0[i]);

			PyDict_SetItemString(
				value, "level", PyInt_FromLong(0));

			PyDict_SetItemString(result, s, value);
		}

		break;
	case 1:
		result = PyDict_New();

		for(i = 0; i < num_printers; i++) {
			PyObject *value;
			fstring s;

			rpcstr_pull(s, ctr.printers_1[i].name.buffer,
				    sizeof(fstring), -1, STR_TERMINATE);

			py_from_PRINTER_INFO_1(&value, &ctr.printers_1[i]);

			PyDict_SetItemString(
				value, "level", PyInt_FromLong(1));

			PyDict_SetItemString(result, s, value);
		}
		
		break;
	case 2:
		result = PyDict_New();

		for(i = 0; i < num_printers; i++) {
			PyObject *value;
			fstring s;

			rpcstr_pull(s, ctr.printers_2[i].printername.buffer,
				    sizeof(fstring), -1, STR_TERMINATE);

			py_from_PRINTER_INFO_2(&value, &ctr.printers_2[i]);

			PyDict_SetItemString(
				value, "level", PyInt_FromLong(2));

			PyDict_SetItemString(result, s, value);
		}
		
		break;
	default:
		PyErr_SetString(spoolss_error, "unknown info level");
		goto done;
	}

done:
	if (cli)
		cli_shutdown(cli);

	if (mem_ctx)
		talloc_destroy(mem_ctx);

	return result;
}
Beispiel #25
0
NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	char *krb5_cc_env = NULL;

	if (stat_ctx && libnetapi_initialized) {
		*context = stat_ctx;
		return NET_API_STATUS_SUCCESS;
	}

#if 0
	talloc_enable_leak_report();
#endif
	frame = talloc_stackframe();

	ctx = talloc_zero(frame, struct libnetapi_ctx);
	if (!ctx) {
		TALLOC_FREE(frame);
		return W_ERROR_V(WERR_NOMEM);
	}

	if (!DEBUGLEVEL) {
		DEBUGLEVEL = 0;
	}

	/* prevent setup_logging() from closing x_stderr... */
	dbf = 0;
	setup_logging("libnetapi", true);

	dbf = x_stderr;
	x_setbuf(x_stderr, NULL);
	AllowDebugChange = false;

	load_case_tables();

	if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) {
		TALLOC_FREE(frame);
		fprintf(stderr, "lp_load failed\n");
		return W_ERROR_V(WERR_GENERAL_FAILURE);
	}

	AllowDebugChange = true;

	init_names();
	load_interfaces();
	reopen_logs();

	BlockSignals(True, SIGPIPE);

	krb5_cc_env = getenv(KRB5_ENV_CCNAME);
	if (!krb5_cc_env || (strlen(krb5_cc_env) == 0)) {
		ctx->krb5_cc_env = talloc_strdup(frame, "MEMORY:libnetapi");
		setenv(KRB5_ENV_CCNAME, ctx->krb5_cc_env, 1);
	}

	if (getenv("USER")) {
		ctx->username = talloc_strdup(frame, getenv("USER"));
	} else {
		ctx->username = talloc_strdup(frame, "");
	}
	if (!ctx->username) {
		TALLOC_FREE(frame);
		fprintf(stderr, "libnetapi_init: out of memory\n");
		return W_ERROR_V(WERR_NOMEM);
	}

	status = libnetapi_init_private_context(ctx);
	if (status != 0) {
		TALLOC_FREE(frame);
		return status;
	}

	libnetapi_initialized = true;

	*context = stat_ctx = ctx;

	return NET_API_STATUS_SUCCESS;
}
Beispiel #26
0
/*
  push a WERROR
*/
_PUBLIC_ enum ndr_err_code ndr_push_WERROR(struct ndr_push *ndr, int ndr_flags, WERROR status)
{
	return ndr_push_uint32(ndr, NDR_SCALARS, W_ERROR_V(status));
}
Beispiel #27
0
static int map_ldb_error(TALLOC_CTX *mem_ctx, int ldb_err,
	const char *add_err_string, const char **errstring)
{
	WERROR err;

	/* Certain LDB modules need to return very special WERROR codes. Proof
	 * for them here and if they exist skip the rest of the mapping. */
	if (add_err_string != NULL) {
		char *endptr;
		strtol(add_err_string, &endptr, 16);
		if (endptr != add_err_string) {
			*errstring = add_err_string;
			return ldb_err;
		}
	}

	/* Otherwise we calculate here a generic, but appropriate WERROR. */

	switch (ldb_err) {
	case LDB_SUCCESS:
		err = WERR_OK;
	break;
	case LDB_ERR_OPERATIONS_ERROR:
		err = WERR_DS_OPERATIONS_ERROR;
	break;
	case LDB_ERR_PROTOCOL_ERROR:
		err = WERR_DS_PROTOCOL_ERROR;
	break;
	case LDB_ERR_TIME_LIMIT_EXCEEDED:
		err = WERR_DS_TIMELIMIT_EXCEEDED;
	break;
	case LDB_ERR_SIZE_LIMIT_EXCEEDED:
		err = WERR_DS_SIZELIMIT_EXCEEDED;
	break;
	case LDB_ERR_COMPARE_FALSE:
		err = WERR_DS_COMPARE_FALSE;
	break;
	case LDB_ERR_COMPARE_TRUE:
		err = WERR_DS_COMPARE_TRUE;
	break;
	case LDB_ERR_AUTH_METHOD_NOT_SUPPORTED:
		err = WERR_DS_AUTH_METHOD_NOT_SUPPORTED;
	break;
	case LDB_ERR_STRONG_AUTH_REQUIRED:
		err = WERR_DS_STRONG_AUTH_REQUIRED;
	break;
	case LDB_ERR_REFERRAL:
		err = WERR_DS_REFERRAL;
	break;
	case LDB_ERR_ADMIN_LIMIT_EXCEEDED:
		err = WERR_DS_ADMIN_LIMIT_EXCEEDED;
	break;
	case LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION:
		err = WERR_DS_UNAVAILABLE_CRIT_EXTENSION;
	break;
	case LDB_ERR_CONFIDENTIALITY_REQUIRED:
		err = WERR_DS_CONFIDENTIALITY_REQUIRED;
	break;
	case LDB_ERR_SASL_BIND_IN_PROGRESS:
		err = WERR_DS_BUSY;
	break;
	case LDB_ERR_NO_SUCH_ATTRIBUTE:
		err = WERR_DS_NO_ATTRIBUTE_OR_VALUE;
	break;
	case LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE:
		err = WERR_DS_ATTRIBUTE_TYPE_UNDEFINED;
	break;
	case LDB_ERR_INAPPROPRIATE_MATCHING:
		err = WERR_DS_INAPPROPRIATE_MATCHING;
	break;
	case LDB_ERR_CONSTRAINT_VIOLATION:
		err = WERR_DS_CONSTRAINT_VIOLATION;
	break;
	case LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS:
		err = WERR_DS_ATTRIBUTE_OR_VALUE_EXISTS;
	break;
	case LDB_ERR_INVALID_ATTRIBUTE_SYNTAX:
		err = WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
	break;
	case LDB_ERR_NO_SUCH_OBJECT:
		err = WERR_DS_NO_SUCH_OBJECT;
	break;
	case LDB_ERR_ALIAS_PROBLEM:
		err = WERR_DS_ALIAS_PROBLEM;
	break;
	case LDB_ERR_INVALID_DN_SYNTAX:
		err = WERR_DS_INVALID_DN_SYNTAX;
	break;
	case LDB_ERR_ALIAS_DEREFERENCING_PROBLEM:
		err = WERR_DS_ALIAS_DEREF_PROBLEM;
	break;
	case LDB_ERR_INAPPROPRIATE_AUTHENTICATION:
		err = WERR_DS_INAPPROPRIATE_AUTH;
	break;
	case LDB_ERR_INVALID_CREDENTIALS:
		err = WERR_ACCESS_DENIED;
	break;
	case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
		err = WERR_DS_INSUFF_ACCESS_RIGHTS;
	break;
	case LDB_ERR_BUSY:
		err = WERR_DS_BUSY;
	break;
	case LDB_ERR_UNAVAILABLE:
		err = WERR_DS_UNAVAILABLE;
	break;
	case LDB_ERR_UNWILLING_TO_PERFORM:
		err = WERR_DS_UNWILLING_TO_PERFORM;
	break;
	case LDB_ERR_LOOP_DETECT:
		err = WERR_DS_LOOP_DETECT;
	break;
	case LDB_ERR_NAMING_VIOLATION:
		err = WERR_DS_NAMING_VIOLATION;
	break;
	case LDB_ERR_OBJECT_CLASS_VIOLATION:
		err = WERR_DS_OBJ_CLASS_VIOLATION;
	break;
	case LDB_ERR_NOT_ALLOWED_ON_NON_LEAF:
		err = WERR_DS_CANT_ON_NON_LEAF;
	break;
	case LDB_ERR_NOT_ALLOWED_ON_RDN:
		err = WERR_DS_CANT_ON_RDN;
	break;
	case LDB_ERR_ENTRY_ALREADY_EXISTS:
		err = WERR_DS_OBJ_STRING_NAME_EXISTS;
	break;
	case LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED:
		err = WERR_DS_CANT_MOD_OBJ_CLASS;
	break;
	case LDB_ERR_AFFECTS_MULTIPLE_DSAS:
		err = WERR_DS_AFFECTS_MULTIPLE_DSAS;
	break;
	default:
		err = WERR_DS_GENERIC_ERROR;
	break;
	}

	*errstring = talloc_asprintf(mem_ctx, "%08X: %s", W_ERROR_V(err),
		add_err_string != NULL ? add_err_string : ldb_strerror(ldb_err));

	/* result is 1:1 for now */
	return ldb_err;
}