server->type = NTPTR_HANDLE_SERVER;
server->ntptr = ntptr;
- server->access_mask = r->in.access_mask;
+ server->object_name = talloc_strdup(server, server_name);
+ W_ERROR_HAVE_NO_MEMORY(server->object_name);
+ server->access_mask = 0;
server->private_data = NULL;
*_server = server;
union spoolss_FormInfo *info;
count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, NULL,
- "(&(objectclass=form))");
+ "(&(objectClass=form))");
if (count == 0) return WERR_OK;
if (count < 0) return WERR_GENERAL_FAILURE;
return WERR_OK;
}
-static WERROR sptr_GetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
- struct spoolss_GetForm *r)
-{
- struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
- struct ldb_message **msgs;
- int count;
- union spoolss_FormInfo *info;
-
- /* TODO: do checks access here
- * if (!(server->access_mask & desired_access)) {
- * return WERR_FOOBAR;
- * }
- */
-
- count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, NULL,
- "(&(form_name=%s)(objectClass=form))",
- r->in.form_name);
-
- if (count == 0) return WERR_FOOBAR;
- if (count > 1) return WERR_FOOBAR;
- if (count < 0) return WERR_GENERAL_FAILURE;
-
- info = talloc(mem_ctx, union spoolss_FormInfo);
- W_ERROR_HAVE_NO_MEMORY(info);
-
- switch (r->in.level) {
- case 1:
- info->info1.flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
-
- info->info1.form_name = samdb_result_string(msgs[0], "form_name", NULL);
- W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
-
- info->info1.size.width = samdb_result_uint(msgs[0], "size_width", 0);
- info->info1.size.height = samdb_result_uint(msgs[0], "size_height", 0);
-
- info->info1.area.left = samdb_result_uint(msgs[0], "area_left", 0);
- info->info1.area.top = samdb_result_uint(msgs[0], "area_top", 0);
- info->info1.area.right = samdb_result_uint(msgs[0], "area_right", 0);
- info->info1.area.bottom = samdb_result_uint(msgs[0], "area_bottom", 0);
- break;
- default:
- return WERR_UNKNOWN_LEVEL;
- }
-
- r->out.info = info;
- return WERR_OK;
-}
-
static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
struct spoolss_SetForm *r)
{
return WERR_OK;
}
+/* Printer Form functions */
+static WERROR sptr_GetPrinterForm(struct ntptr_GenericHandle *printer, TALLOC_CTX *mem_ctx,
+ struct spoolss_GetForm *r)
+{
+ struct ldb_context *sptr_db = talloc_get_type(printer->ntptr->private_data, struct ldb_context);
+ struct ldb_message **msgs;
+ const char *base_dn;
+ int count;
+ union spoolss_FormInfo *info;
+
+ /* TODO: do checks access here
+ * if (!(printer->access_mask & desired_access)) {
+ * return WERR_FOOBAR;
+ * }
+ */
+
+ base_dn = talloc_asprintf(mem_ctx, "CN=Forms,CN=%s,CN=Printers", printer->object_name);
+ W_ERROR_HAVE_NO_MEMORY(base_dn);
+
+ count = sptr_db_search(sptr_db, mem_ctx, base_dn, &msgs, NULL,
+ "(&(form_name=%s)(objectClass=form))",
+ r->in.form_name);
+
+ if (count == 0) return WERR_FOOBAR;
+ if (count > 1) return WERR_FOOBAR;
+ if (count < 0) return WERR_GENERAL_FAILURE;
+
+ info = talloc(mem_ctx, union spoolss_FormInfo);
+ W_ERROR_HAVE_NO_MEMORY(info);
+
+ switch (r->in.level) {
+ case 1:
+ info->info1.flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
+
+ info->info1.form_name = samdb_result_string(msgs[0], "form_name", NULL);
+ W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
+
+ info->info1.size.width = samdb_result_uint(msgs[0], "size_width", 0);
+ info->info1.size.height = samdb_result_uint(msgs[0], "size_height", 0);
+
+ info->info1.area.left = samdb_result_uint(msgs[0], "area_left", 0);
+ info->info1.area.top = samdb_result_uint(msgs[0], "area_top", 0);
+ info->info1.area.right = samdb_result_uint(msgs[0], "area_right", 0);
+ info->info1.area.bottom = samdb_result_uint(msgs[0], "area_bottom", 0);
+ break;
+ default:
+ return WERR_UNKNOWN_LEVEL;
+ }
+
+ r->out.info = info;
+ return WERR_OK;
+}
+
+
/*
initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
*/
/* PrintServer Form functions */
.EnumPrintServerForms = sptr_EnumPrintServerForms,
.AddPrintServerForm = sptr_AddPrintServerForm,
- .GetPrintServerForm = sptr_GetPrintServerForm,
.SetPrintServerForm = sptr_SetPrintServerForm,
.DeletePrintServerForm = sptr_DeletePrintServerForm,
/* Printer Form functions */
/* .EnumPrinterForms = sptr_EnumPrinterForms,
.AddPrinterForm = sptr_AddPrinterForm,
- .GetPrinterForm = sptr_GetPrinterForm,
- .SetPrinterForm = sptr_SetPrinterForm,
+*/ .GetPrinterForm = sptr_GetPrinterForm,
+/* .SetPrinterForm = sptr_SetPrinterForm,
.DeletePrinterForm = sptr_DeletePrinterForm,
*/
/* Printer Job functions */
const char *server_name)
{
BOOL ret;
- const char *ip_str;
+ char *str;
+ /* NULL is ok */
if (!server_name) return WERR_OK;
+ /* "" is ok */
ret = strequal("",server_name);
if (ret) return WERR_OK;
+ /* just "\\" is invalid */
+ if (strequal("\\\\", server_name)) {
+ return WERR_INVALID_PRINTER_NAME;
+ }
+
+ /* then we need "\\" */
if (strncmp("\\\\", server_name, 2) != 0) {
return WERR_INVALID_PRINTER_NAME;
}
server_name += 2;
+ /* NETBIOS NAME is ok */
ret = strequal(lp_netbios_name(), server_name);
if (ret) return WERR_OK;
- /* TODO: check dns name here ? */
+ /* DNS NAME is ok
+ * TODO: we need to check if aliases are also ok
+ */
+ if (lp_realm() != NULL) {
+ str = talloc_asprintf(mem_ctx, "%s.%s",
+ lp_netbios_name(),
+ lp_realm());
+ W_ERROR_HAVE_NO_MEMORY(str);
+
+ ret = strequal(str, server_name);
+ talloc_free(str);
+ if (ret) return WERR_OK;
+ }
- ip_str = socket_get_my_addr(dce_call->conn->srv_conn->socket, mem_ctx);
- W_ERROR_HAVE_NO_MEMORY(ip_str);
+ str = socket_get_my_addr(dce_call->conn->srv_conn->socket, mem_ctx);
+ W_ERROR_HAVE_NO_MEMORY(str);
- ret = strequal(ip_str, server_name);
+ ret = strequal(str, server_name);
+ talloc_free(str);
if (ret) return WERR_OK;
return WERR_INVALID_PRINTER_NAME;
switch (handle->type) {
case NTPTR_HANDLE_SERVER:
- status = ntptr_GetPrintServerForm(handle, mem_ctx, r);
- W_ERROR_NOT_OK_RETURN(status);
- break;
+ /*
+ * stupid, but w2k3 returns WERR_BADFID here?
+ */
+ return WERR_BADFID;
case NTPTR_HANDLE_PRINTER:
status = ntptr_GetPrinterForm(handle, mem_ctx, r);
W_ERROR_NOT_OK_RETURN(status);
r.in.buffer = &blob;
r.in.offered = r.out.needed;
status = dcerpc_spoolss_GetForm(p, mem_ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("GetForm failed - %s\n",
+ nt_errstr(status));
+ return False;
+ }
+
+ if (!W_ERROR_IS_OK(r.out.result)) {
+ printf("GetForm failed - %s\n",
+ win_errstr(r.out.result));
+ return False;
+ }
if (!r.out.info) {
printf("No form info returned\n");
}
}
+
+ if (!W_ERROR_IS_OK(r.out.result)) {
+ printf("GetForm failed - %s\n",
+ win_errstr(r.out.result));
+ return False;
+ }
+
return True;
}
{
NTSTATUS status;
struct spoolss_EnumForms r;
+ BOOL ret = True;
r.in.handle = handle;
r.in.level = 1;
info = r.out.info;
for (j = 0; j < r.out.count; j++) {
- test_GetForm(p, mem_ctx, handle, info[j].info1.form_name);
+ if (!print_server) ret &= test_GetForm(p, mem_ctx, handle, info[j].info1.form_name);
}
}
}
static BOOL test_AddForm(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
- struct policy_handle *handle)
+ struct policy_handle *handle, BOOL print_server)
{
struct spoolss_AddForm r;
struct spoolss_AddFormInfo1 addform;
}
if (!W_ERROR_IS_OK(r.out.result)) {
- printf("AddForm failed - %s\n", nt_errstr(status));
+ printf("AddForm failed - %s\n", win_errstr(r.out.result));
goto done;
}
+ if (!print_server) ret &= test_GetForm(p, mem_ctx, handle, form_name);
+
{
struct spoolss_SetForm sf;
struct spoolss_AddFormInfo1 setform;
}
}
+ if (!print_server) ret &= test_GetForm(p, mem_ctx, handle, form_name);
+
done:
if (!test_DeleteForm(p, mem_ctx, handle, form_name)) {
printf("DeleteForm failed\n");
ret = False;
}
- if (!test_AddForm(p, mem_ctx, &handle)) {
+ if (!test_AddForm(p, mem_ctx, &handle, False)) {
ret = False;
}
ret &= test_EnumForms(ctx->p, ctx, &ctx->server_handle, True);
+ ret &= test_AddForm(ctx->p, ctx, &ctx->server_handle, True);
+
ret &= test_EnumPorts(ctx);
ret &= test_GetPrinterDriverDirectory(ctx);