Ejemplo n.º 1
0
PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw)
{
	static char *kwlist[] = { "server", "printername", "info", "creds", 
				  NULL};
	char *printername, *server, *errstr;
	PyObject *info, *result = NULL, *creds = NULL;
	struct cli_state *cli = NULL;
	TALLOC_CTX *mem_ctx = NULL;
	PRINTER_INFO_CTR ctr;
	PRINTER_INFO_2 info2;
	WERROR werror;

	if (!PyArg_ParseTupleAndKeywords(
		    args, kw, "ssO!|O!", kwlist, &server, &printername,
		    &PyDict_Type, &info, &PyDict_Type, &creds))
		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_addprinterex"))) {
		PyErr_SetString(
			spoolss_error, "unable to init talloc context\n");
		goto done;
	}

	if (!py_to_PRINTER_INFO_2(&info2, info, mem_ctx)) {
		PyErr_SetString(spoolss_error,
				"error converting to printer info 2");
		goto done;
	}

	ctr.printers_2 = &info2;

	werror = cli_spoolss_addprinterex(cli, mem_ctx, 2, &ctr);

	Py_INCREF(Py_None);
	result = Py_None;

done:
	if (cli)
		cli_shutdown(cli);

	if (mem_ctx)
		talloc_destroy(mem_ctx);

	return result;
}
Ejemplo n.º 2
0
PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw)
{
	char *unc_name, *server, *errstr;
	TALLOC_CTX *mem_ctx = NULL;
	POLICY_HND hnd;
	WERROR werror;
	PyObject *result = NULL, *creds = NULL;
	static char *kwlist[] = { "printername", "creds", "access", NULL };
	uint32 desired_access = MAXIMUM_ALLOWED_ACCESS;
	struct cli_state *cli;

	if (!PyArg_ParseTupleAndKeywords(
		    args, kw, "s|Oi", kwlist, &unc_name, &creds,
		    &desired_access))
		return NULL;

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

	server = strdup(unc_name + 2);

	if (strchr(server, '\\')) {
		char *c = strchr(server, '\\');
		*c = 0;
	}

	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_openprinter"))) {
		PyErr_SetString(spoolss_error, 
				"unable to init talloc context\n");
		goto done;
	}

	werror = cli_spoolss_open_printer_ex(
		cli, mem_ctx, unc_name, "", desired_access, server, 
		"", &hnd);

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

	result = new_spoolss_policy_hnd_object(cli, mem_ctx, &hnd);

 done:
	if (!result) {
		if (cli)
			cli_shutdown(cli);

		if (mem_ctx)
			talloc_destroy(mem_ctx);
	}

	SAFE_FREE(server);

	return result;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args,
				   PyObject *kw)
{
	static char *kwlist[] = { "server", "info", "creds", NULL };
	char *server, *errstr;
	uint32 level;
	PyObject *info, *result = NULL, *creds = NULL;
	WERROR werror;
	TALLOC_CTX *mem_ctx = NULL;
	struct cli_state *cli = NULL;
	PRINTER_DRIVER_CTR ctr;
	union {
		DRIVER_INFO_3 driver_3;
	} dinfo;

	if (!PyArg_ParseTupleAndKeywords(
		    args, kw, "sO!|O", kwlist, &server, &PyDict_Type,
		    &info, &creds))
		return NULL;
	
	if (server[0] == '\\' || server[1] == '\\')
		server += 2;

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

	if (!(mem_ctx = talloc_init("spoolss_addprinterdriver"))) {
		PyErr_SetString(
			spoolss_error, "unable to init talloc context\n");
		return NULL;
	}

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

	if (!get_level_value(info, &level)) {
		PyErr_SetString(spoolss_error, "invalid info level");
		goto done;
	}

	if (level != 3) {
		PyErr_SetString(spoolss_error, "unsupported info level");
		goto done;
	}

	ZERO_STRUCT(ctr);
	ZERO_STRUCT(dinfo);

	switch(level) {
	case 3:
		ctr.info3 = &dinfo.driver_3;

		if (!py_to_DRIVER_INFO_3(&dinfo.driver_3, info)) {
			PyErr_SetString(spoolss_error,
					"error converting to driver info 3");
			goto done;
		}

		break;
	default:
		PyErr_SetString(spoolss_error, "unsupported info level");
		goto done;
	}

	werror = cli_spoolss_addprinterdriver(cli, mem_ctx, level, &ctr);

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

	Py_INCREF(Py_None);
	result = Py_None;

done:
	if (cli)
		cli_shutdown(cli);

	if (mem_ctx)
		talloc_destroy(mem_ctx);
	
	return result;
	
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
PyObject *srvsvc_netservergetinfo(PyObject *self, PyObject *args,
                                  PyObject *kw)
{
    static char *kwlist[] = { "server", "level", "creds", NULL };
    char *unc_name, *server, *errstr;
    PyObject *creds = NULL, *result = NULL;
    struct cli_state *cli;
    TALLOC_CTX *mem_ctx = NULL;
    uint32 level;
    SRV_INFO_CTR ctr;
    WERROR status;

    if (!PyArg_ParseTupleAndKeywords(
                args, kw, "si|O", kwlist, &unc_name, &level, &creds))
        return NULL;

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

    server = SMB_STRDUP(unc_name + 2);

    if (strchr(server, '\\')) {
        char *c = strchr(server, '\\');
        *c = 0;
    }

    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_SRVSVC, &errstr))) {
        PyErr_SetString(srvsvc_error, errstr);
        free(errstr);
        goto done;
    }

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

    ZERO_STRUCT(ctr);

    status = rpccli_srvsvc_net_srv_get_info(cli->pipe_list, mem_ctx, level, &ctr);

    if (!NT_STATUS_IS_OK(status)) {
        PyErr_SetObject(srvsvc_error, py_werror_tuple(status));
        goto done;
    }

    if (level != ctr.switch_value) {
        PyErr_SetString(srvsvc_error, "container level value wrong");
        goto done;
    }

    switch(level) {
    case 101:
        py_from_SRV_INFO_101(&result, &ctr.srv.sv101);
        break;
    }

    Py_INCREF(result);

done:
    if (mem_ctx)
        talloc_destroy(mem_ctx);

    return result;
}
Ejemplo n.º 8
0
static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw)
{
	static char *kwlist[] = { "server", "creds", "access", NULL };
	uint32 desired_access = MAXIMUM_ALLOWED_ACCESS;
	char *server, *errstr;
	struct cli_state *cli = NULL;
	POLICY_HND hnd;
	TALLOC_CTX *mem_ctx = NULL;
	PyObject *result = NULL, *creds = NULL;
	NTSTATUS ntstatus;

	if (!PyArg_ParseTupleAndKeywords(
		    args, kw, "s|Oi", kwlist, &server, &creds,
		    &desired_access)) 
		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_SAMR, &errstr))) {
		PyErr_SetString(samr_error, errstr);
		free(errstr);
		return NULL;
	}

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

	ntstatus = rpccli_samr_connect(cli->pipe_list, mem_ctx, desired_access, &hnd);

	if (!NT_STATUS_IS_OK(ntstatus)) {
		cli_shutdown(cli);
		PyErr_SetObject(samr_ntstatus, py_ntstatus_tuple(ntstatus));
		goto done;
	}

	result = new_samr_connect_hnd_object(cli->pipe_list, mem_ctx, &hnd);

done:
	if (!result) {
		if (cli)
			cli_shutdown(cli);

		if (mem_ctx)
			talloc_destroy(mem_ctx);
	}

	return result;
}