source4/: Fix prototypes for all functions in various subsystems.
[sfrench/samba-autobuild/.git] / source4 / ntptr / simple_ldb / ntptr_simple_ldb.c
index dc79ba8a1adac109192f2cb9ba569d73a7d938f5..c25c61d36bb16222094cbc65e26c56c365e695ac 100644 (file)
@@ -7,7 +7,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 /*
   This implements a NTPTR backend that store
 #include "includes.h"
 #include "ntptr/ntptr.h"
 #include "librpc/gen_ndr/ndr_spoolss.h"
-#include "lib/ldb/include/ldb.h"
-#include "db_wrap.h"
+#include <ldb.h>
+#include "auth/auth.h"
+#include "dsdb/samdb/samdb.h"
+#include "ldb_wrap.h"
+#include "../lib/util/util_ldb.h"
+#include "librpc/gen_ndr/dcerpc.h"
+#include "rpc_server/dcerpc_server.h"
+#include "rpc_server/common/common.h"
+#include "param/param.h"
+
+NTSTATUS ntptr_simple_ldb_init(void);
 
 /*
   connect to the SPOOLSS database
   return a ldb_context pointer on success, or NULL on failure
  */
-static struct ldb_context *sptr_db_connect(TALLOC_CTX *mem_ctx)
+static struct ldb_context *sptr_db_connect(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx, struct loadparm_context *lp_ctx)
 {
-       return ldb_wrap_connect(mem_ctx, lp_spoolss_url(), 0, NULL);
+       return ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx, lpcfg_spoolss_url(lp_ctx), system_session(lp_ctx),
+                               NULL, 0);
 }
 
 static int sptr_db_search(struct ldb_context *ldb,
                          TALLOC_CTX *mem_ctx,
-                         const char *basedn,
+                         struct ldb_dn *basedn,
                          struct ldb_message ***res,
                          const char * const *attrs,
                          const char *format, ...) PRINTF_ATTRIBUTE(6,7);
 
 static int sptr_db_search(struct ldb_context *ldb,
                          TALLOC_CTX *mem_ctx,
-                         const char *basedn,
+                         struct ldb_dn *basedn,
                          struct ldb_message ***res,
                          const char * const *attrs,
                          const char *format, ...)
@@ -69,20 +78,20 @@ static int sptr_db_search(struct ldb_context *ldb,
 
 #define SET_STRING(ldb, mod, attr, value) do { \
        if (value == NULL) return WERR_INVALID_PARAM; \
-       if (samdb_msg_add_string(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
+       if (ldb_msg_add_string(mod, attr, value) != LDB_SUCCESS) { \
                return WERR_NOMEM; \
        } \
 } while (0)
 
 #define SET_UINT(ldb, mod, attr, value) do { \
-       if (samdb_msg_add_uint(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
+       if (samdb_msg_add_uint(ldb, (TALLOC_CTX *)mod, mod, attr, value) != LDB_SUCCESS) { \
                return WERR_NOMEM; \
        } \
 } while (0)
 
 static NTSTATUS sptr_init_context(struct ntptr_context *ntptr)
 {
-       struct ldb_context *sptr_db = sptr_db_connect(ntptr);
+       struct ldb_context *sptr_db = sptr_db_connect(ntptr, ntptr->ev_ctx, ntptr->lp_ctx);
        NT_STATUS_HAVE_NO_MEMORY(sptr_db);
 
        ntptr->private_data = sptr_db;
@@ -105,7 +114,9 @@ static WERROR sptr_OpenPrintServer(struct ntptr_context *ntptr, TALLOC_CTX *mem_
 
        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;
@@ -115,54 +126,139 @@ static WERROR sptr_OpenPrintServer(struct ntptr_context *ntptr, TALLOC_CTX *mem_
 /*
  * PrintServer PrinterData functions
  */
-static WERROR sptr_GetPrintServerData(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
-                                     struct spoolss_GetPrinterData *r)
+
+static WERROR sptr_PrintServerData(struct ntptr_GenericHandle *server,
+                                  TALLOC_CTX *mem_ctx,
+                                  const char *value_name,
+                                  union spoolss_PrinterData *r,
+                                  enum winreg_Type *type)
 {
-       if (strcmp("W3SvcInstalled", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
-               r->out.data.value       = 0;
+       struct dcerpc_server_info *server_info = lpcfg_dcerpc_server_info(mem_ctx, server->ntptr->lp_ctx);
+       if (strcmp("W3SvcInstalled", value_name) == 0) {
+               *type           = REG_DWORD;
+               r->value        = 0;
                return WERR_OK;
-       } else if (strcmp("BeepEnabled", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
-               r->out.data.value       = 0;
+       } else if (strcmp("BeepEnabled", value_name) == 0) {
+               *type           = REG_DWORD;
+               r->value        = 0;
                return WERR_OK;
-       } else if (strcmp("EventLog", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
-               r->out.data.value       = 0;
+       } else if (strcmp("EventLog", value_name) == 0) {
+               *type           = REG_DWORD;
+               r->value        = 0;
                return WERR_OK;
-       } else if (strcmp("NetPopup", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
-               r->out.data.value       = 0;
+       } else if (strcmp("NetPopup", value_name) == 0) {
+               *type           = REG_DWORD;
+               r->value        = 0;
                return WERR_OK;
-       } else if (strcmp("NetPopupToComputer", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
-               r->out.data.value       = 0;
+       } else if (strcmp("NetPopupToComputer", value_name) == 0) {
+               *type           = REG_DWORD;
+               r->value        = 0;
                return  WERR_OK;
-       } else if (strcmp("MajorVersion", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
-               r->out.data.value       = 3;
+       } else if (strcmp("MajorVersion", value_name) == 0) {
+               *type           = REG_DWORD;
+               r->value        = 3;
                return WERR_OK;
-       } else if (strcmp("MinorVersion", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
-               r->out.data.value       = 0;
+       } else if (strcmp("MinorVersion", value_name) == 0) {
+               *type           = REG_DWORD;
+               r->value        = 0;
                return WERR_OK;
-       } else if (strcmp("DefaultSpoolDirectory", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_STRING;
-               r->out.data.string      = "C:\\PRINTERS";
+       } else if (strcmp("DefaultSpoolDirectory", value_name) == 0) {
+               *type           = REG_SZ;
+               r->string       = "C:\\PRINTERS";
                return  WERR_OK;
-       } else if (strcmp("Architecture", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_STRING;
-               r->out.data.string      = SPOOLSS_ARCHITECTURE_NT_X86;
+       } else if (strcmp("Architecture", value_name) == 0) {
+               *type           = REG_SZ;
+               r->string       = SPOOLSS_ARCHITECTURE_NT_X86;
                return  WERR_OK;
-       } else if (strcmp("DsPresent", r->in.value_name) == 0) {
-               r->out.type             = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
-               r->out.data.value       = 1;
+       } else if (strcmp("DsPresent", value_name) == 0) {
+               *type           = REG_DWORD;
+               r->value        = 1;
+               return WERR_OK;
+       } else if (strcmp("OSVersion", value_name) == 0) {
+               DATA_BLOB blob;
+               enum ndr_err_code ndr_err;
+               struct spoolss_OSVersion os;
+
+               os.major                = server_info->version_major;
+               os.minor                = server_info->version_minor;
+               os.build                = server_info->version_build;
+               os.extra_string         = "";
+
+               ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
+               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+                       return WERR_GENERAL_FAILURE;
+               }
+
+               *type           = REG_BINARY;
+               r->binary       = blob;
+               return WERR_OK;
+       } else if (strcmp("OSVersionEx", value_name) == 0) {
+               DATA_BLOB blob;
+               enum ndr_err_code ndr_err;
+               struct spoolss_OSVersionEx os_ex;
+
+               os_ex.major             = server_info->version_major;
+               os_ex.minor             = server_info->version_minor;
+               os_ex.build             = server_info->version_build;
+               os_ex.extra_string      = "";
+               os_ex.service_pack_major= 0;
+               os_ex.service_pack_minor= 0;
+               os_ex.suite_mask        = 0;
+               os_ex.product_type      = 0;
+               os_ex.reserved          = 0;
+
+               ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os_ex, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersionEx);
+               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+                       return WERR_GENERAL_FAILURE;
+               }
+
+               *type           = REG_BINARY;
+               r->binary       = blob;
+               return WERR_OK;
+       } else if (strcmp("DNSMachineName", value_name) == 0) {
+               const char *dnsdomain = lpcfg_dnsdomain(server->ntptr->lp_ctx);
+
+               if (dnsdomain == NULL) return WERR_INVALID_PARAM;
+
+               *type           = REG_SZ;
+               r->string       = talloc_asprintf(mem_ctx, "%s.%s",
+                                                         lpcfg_netbios_name(server->ntptr->lp_ctx),
+                                                         dnsdomain);
+               W_ERROR_HAVE_NO_MEMORY(r->string);
                return WERR_OK;
        }
 
        return WERR_INVALID_PARAM;
 }
 
+static WERROR sptr_GetPrintServerData(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
+                                     struct spoolss_GetPrinterData *r)
+{
+       WERROR result;
+       union spoolss_PrinterData data;
+       DATA_BLOB blob;
+       enum ndr_err_code ndr_err;
+
+       result = sptr_PrintServerData(server, mem_ctx, r->in.value_name, &data, r->out.type);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
+       ndr_err = ndr_push_union_blob(&blob, mem_ctx, 
+                                     &data, *r->out.type, (ndr_push_flags_fn_t)ndr_push_spoolss_PrinterData);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return WERR_GENERAL_FAILURE;
+       }
+
+       *r->out.needed = blob.length;
+
+       if (r->in.offered >= *r->out.needed) {
+               memcpy(r->out.data, blob.data, blob.length);
+       }
+
+       return WERR_OK;
+}
+
 /* PrintServer Form functions */
 static WERROR sptr_EnumPrintServerForms(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
                                        struct spoolss_EnumForms *r)
@@ -173,8 +269,9 @@ static WERROR sptr_EnumPrintServerForms(struct ntptr_GenericHandle *server, TALL
        int i;
        union spoolss_FormInfo *info;
 
-       count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, NULL,
-                              "(&(objectclass=form))");
+       count = sptr_db_search(sptr_db, mem_ctx,
+                               ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
+                               &msgs, NULL, "(&(objectClass=form))");
 
        if (count == 0) return WERR_OK;
        if (count < 0) return WERR_GENERAL_FAILURE;
@@ -185,26 +282,26 @@ static WERROR sptr_EnumPrintServerForms(struct ntptr_GenericHandle *server, TALL
        switch (r->in.level) {
        case 1:
                for (i=0; i < count; i++) {
-                       info[i].info1.flags             = samdb_result_uint(msgs[i], "flags", SPOOLSS_FORM_BUILTIN);
+                       info[i].info1.flags             = ldb_msg_find_attr_as_uint(msgs[i], "flags", SPOOLSS_FORM_BUILTIN);
 
-                       info[i].info1.form_name         = samdb_result_string(msgs[i], "form_name", NULL);
+                       info[i].info1.form_name         = ldb_msg_find_attr_as_string(msgs[i], "form-name", NULL);
                        W_ERROR_HAVE_NO_MEMORY(info[i].info1.form_name);
 
-                       info[i].info1.size.width        = samdb_result_uint(msgs[i], "size_width", 0);
-                       info[i].info1.size.height       = samdb_result_uint(msgs[i], "size_height", 0);
+                       info[i].info1.size.width        = ldb_msg_find_attr_as_uint(msgs[i], "size-width", 0);
+                       info[i].info1.size.height       = ldb_msg_find_attr_as_uint(msgs[i], "size-height", 0);
 
-                       info[i].info1.area.left         = samdb_result_uint(msgs[i], "area_left", 0);
-                       info[i].info1.area.top          = samdb_result_uint(msgs[i], "area_top", 0);
-                       info[i].info1.area.right        = samdb_result_uint(msgs[i], "area_right", 0);
-                       info[i].info1.area.bottom       = samdb_result_uint(msgs[i], "area_bottom", 0);
+                       info[i].info1.area.left         = ldb_msg_find_attr_as_uint(msgs[i], "area-left", 0);
+                       info[i].info1.area.top          = ldb_msg_find_attr_as_uint(msgs[i], "area-top", 0);
+                       info[i].info1.area.right        = ldb_msg_find_attr_as_uint(msgs[i], "area-right", 0);
+                       info[i].info1.area.bottom       = ldb_msg_find_attr_as_uint(msgs[i], "area-bottom", 0);
                }
                break;
        default:
                return WERR_UNKNOWN_LEVEL;
        }
 
-       r->out.info     = info;
-       r->out.count    = count;
+       *r->out.info    = info;
+       *r->out.count   = count;
        return WERR_OK;
 }
 
@@ -227,8 +324,9 @@ static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC
                if (!r->in.info.info1) {
                        return WERR_FOOBAR;
                }
-               count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, attrs,
-                                      "(&(form_name=%s)(objectClass=form))",
+               count = sptr_db_search(sptr_db, mem_ctx,
+                                      ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
+                                      &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
                                       r->in.info.info1->form_name);
 
                if (count == 1) return WERR_FOOBAR;
@@ -243,27 +341,26 @@ static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC
                W_ERROR_HAVE_NO_MEMORY(msg);
 
                /* add core elements to the ldb_message for the Form */
-               msg->dn = talloc_asprintf(msg, "form_name=%s,CN=Forms,CN=PrintServer",
-                                               r->in.info.info1->form_name);
+               msg->dn = ldb_dn_new_fmt(msg, sptr_db, "form-name=%s,CN=Forms,CN=PrintServer", r->in.info.info1->form_name);
                SET_STRING(sptr_db, msg, "objectClass", "form");
 
                SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
 
-               SET_STRING(sptr_db, msg, "form_name", r->in.info.info1->form_name);
+               SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
 
-               SET_UINT(sptr_db, msg, "size_width", r->in.info.info1->size.width);
-               SET_UINT(sptr_db, msg, "size_height", r->in.info.info1->size.height);
+               SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
+               SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
 
-               SET_UINT(sptr_db, msg, "area_left", r->in.info.info1->area.left);
-               SET_UINT(sptr_db, msg, "area_top", r->in.info.info1->area.top);
-               SET_UINT(sptr_db, msg, "area_right", r->in.info.info1->area.right);
-               SET_UINT(sptr_db, msg, "area_bottom", r->in.info.info1->area.bottom);
+               SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
+               SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
+               SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
+               SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
                break;
        default:
                return WERR_UNKNOWN_LEVEL;
        }
 
-       ret = samdb_add(sptr_db, mem_ctx, msg);
+       ret = ldb_add(sptr_db, msg);
        if (ret != 0) {
                return WERR_FOOBAR;
        }
@@ -271,54 +368,6 @@ static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC
        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)
 {
@@ -340,15 +389,16 @@ static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC
                        return WERR_FOOBAR;
                }
 
-               count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, attrs,
-                                      "(&(form_name=%s)(objectClass=form))",
+               count = sptr_db_search(sptr_db, mem_ctx,
+                                      ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
+                                      &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
                                       r->in.info.info1->form_name);
 
                if (count == 0) return WERR_FOOBAR;
                if (count > 1) return WERR_FOOBAR;
                if (count < 0) return WERR_GENERAL_FAILURE;
 
-               flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
+               flags = ldb_msg_find_attr_as_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
                if (flags != SPOOLSS_FORM_USER) {
                        return WERR_FOOBAR;
                }
@@ -361,21 +411,21 @@ static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC
 
                SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
 
-               SET_STRING(sptr_db, msg, "form_name", r->in.info.info1->form_name);
+               SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
 
-               SET_UINT(sptr_db, msg, "size_width", r->in.info.info1->size.width);
-               SET_UINT(sptr_db, msg, "size_height", r->in.info.info1->size.height);
+               SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
+               SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
 
-               SET_UINT(sptr_db, msg, "area_left", r->in.info.info1->area.left);
-               SET_UINT(sptr_db, msg, "area_top", r->in.info.info1->area.top);
-               SET_UINT(sptr_db, msg, "area_right", r->in.info.info1->area.right);
-               SET_UINT(sptr_db, msg, "area_bottom", r->in.info.info1->area.bottom);
+               SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
+               SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
+               SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
+               SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
                break;
        default:
                return WERR_UNKNOWN_LEVEL;
        }
 
-       ret = samdb_replace(sptr_db, mem_ctx, msg);
+       ret = dsdb_replace(sptr_db, msg, 0);
        if (ret != 0) {
                return WERR_FOOBAR;
        }
@@ -402,20 +452,21 @@ static WERROR sptr_DeletePrintServerForm(struct ntptr_GenericHandle *server, TAL
                return WERR_FOOBAR;
        }
 
-       count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, attrs,
-                              "(&(form_name=%s)(objectclass=form))",
+       count = sptr_db_search(sptr_db, mem_ctx,
+                              ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
+                              &msgs, attrs, "(&(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;
 
-       flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
+       flags = ldb_msg_find_attr_as_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
        if (flags != SPOOLSS_FORM_USER) {
                return WERR_FOOBAR;
        }
 
-       ret = samdb_delete(sptr_db, mem_ctx, msgs[0]->dn);
+       ret = ldb_delete(sptr_db, msgs[0]->dn);
        if (ret != 0) {
                return WERR_FOOBAR;
        }
@@ -493,92 +544,92 @@ static WERROR sptr_EnumPrinters(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx
        switch(r->in.level) {
        case 1:
                for (i = 0; i < count; i++) {
-                       info[i].info1.flags             = samdb_result_uint(msgs[i], "flags", 0);
+                       info[i].info1.flags             = ldb_msg_find_attr_as_uint(msgs[i], "flags", 0);
 
-                       info[i].info1.name              = samdb_result_string(msgs[i], "name", "");
+                       info[i].info1.name              = ldb_msg_find_attr_as_string(msgs[i], "name", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info1.name);
 
-                       info[i].info1.description       = samdb_result_string(msgs[i], "description", "");
+                       info[i].info1.description       = ldb_msg_find_attr_as_string(msgs[i], "description", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info1.description);
 
-                       info[i].info1.comment           = samdb_result_string(msgs[i], "comment", NULL);
+                       info[i].info1.comment           = ldb_msg_find_attr_as_string(msgs[i], "comment", NULL);
                }
                break;
        case 2:
                for (i = 0; i < count; i++) {
-                       info[i].info2.servername        = samdb_result_string(msgs[i], "servername", "");
+                       info[i].info2.servername        = ldb_msg_find_attr_as_string(msgs[i], "servername", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
 
-                       info[i].info2.printername       = samdb_result_string(msgs[i], "printername", "");
+                       info[i].info2.printername       = ldb_msg_find_attr_as_string(msgs[i], "printername", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
 
-                       info[i].info2.sharename         = samdb_result_string(msgs[i], "sharename", "");
+                       info[i].info2.sharename         = ldb_msg_find_attr_as_string(msgs[i], "sharename", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.sharename);
 
-                       info[i].info2.portname          = samdb_result_string(msgs[i], "portname", "");
+                       info[i].info2.portname          = ldb_msg_find_attr_as_string(msgs[i], "portname", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.portname);
 
-                       info[i].info2.drivername        = samdb_result_string(msgs[i], "drivername", "");
+                       info[i].info2.drivername        = ldb_msg_find_attr_as_string(msgs[i], "drivername", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.drivername);
 
-                       info[i].info2.comment           = samdb_result_string(msgs[i], "comment", NULL);
+                       info[i].info2.comment           = ldb_msg_find_attr_as_string(msgs[i], "comment", NULL);
 
-                       info[i].info2.location          = samdb_result_string(msgs[i], "location", NULL);
+                       info[i].info2.location          = ldb_msg_find_attr_as_string(msgs[i], "location", NULL);
 
                        info[i].info2.devmode           = NULL;
 
-                       info[i].info2.sepfile           = samdb_result_string(msgs[i], "sepfile", NULL);
+                       info[i].info2.sepfile           = ldb_msg_find_attr_as_string(msgs[i], "sepfile", NULL);
 
-                       info[i].info2.printprocessor    = samdb_result_string(msgs[i], "printprocessor", "");
+                       info[i].info2.printprocessor    = ldb_msg_find_attr_as_string(msgs[i], "printprocessor", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.printprocessor);
 
-                       info[i].info2.datatype          = samdb_result_string(msgs[i], "datatype", "");
+                       info[i].info2.datatype          = ldb_msg_find_attr_as_string(msgs[i], "datatype", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.datatype);
 
-                       info[i].info2.parameters        = samdb_result_string(msgs[i], "parameters", NULL);
+                       info[i].info2.parameters        = ldb_msg_find_attr_as_string(msgs[i], "parameters", NULL);
 
                        info[i].info2.secdesc           = NULL;
 
-                       info[i].info2.attributes        = samdb_result_uint(msgs[i], "attributes", 0);
-                       info[i].info2.priority          = samdb_result_uint(msgs[i], "priority", 0);
-                       info[i].info2.defaultpriority   = samdb_result_uint(msgs[i], "defaultpriority", 0);
-                       info[i].info2.starttime         = samdb_result_uint(msgs[i], "starttime", 0);
-                       info[i].info2.untiltime         = samdb_result_uint(msgs[i], "untiltime", 0);
-                       info[i].info2.status            = samdb_result_uint(msgs[i], "status", 0);
-                       info[i].info2.cjobs             = samdb_result_uint(msgs[i], "cjobs", 0);
-                       info[i].info2.averageppm        = samdb_result_uint(msgs[i], "averageppm", 0);
+                       info[i].info2.attributes        = ldb_msg_find_attr_as_uint(msgs[i], "attributes", 0);
+                       info[i].info2.priority          = ldb_msg_find_attr_as_uint(msgs[i], "priority", 0);
+                       info[i].info2.defaultpriority   = ldb_msg_find_attr_as_uint(msgs[i], "defaultpriority", 0);
+                       info[i].info2.starttime         = ldb_msg_find_attr_as_uint(msgs[i], "starttime", 0);
+                       info[i].info2.untiltime         = ldb_msg_find_attr_as_uint(msgs[i], "untiltime", 0);
+                       info[i].info2.status            = ldb_msg_find_attr_as_uint(msgs[i], "status", 0);
+                       info[i].info2.cjobs             = ldb_msg_find_attr_as_uint(msgs[i], "cjobs", 0);
+                       info[i].info2.averageppm        = ldb_msg_find_attr_as_uint(msgs[i], "averageppm", 0);
                }
                break;
        case 4:
                for (i = 0; i < count; i++) {
-                       info[i].info4.printername       = samdb_result_string(msgs[i], "printername", "");
+                       info[i].info4.printername       = ldb_msg_find_attr_as_string(msgs[i], "printername", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
 
-                       info[i].info4.servername        = samdb_result_string(msgs[i], "servername", "");
+                       info[i].info4.servername        = ldb_msg_find_attr_as_string(msgs[i], "servername", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
 
-                       info[i].info4.attributes        = samdb_result_uint(msgs[i], "attributes", 0);
+                       info[i].info4.attributes        = ldb_msg_find_attr_as_uint(msgs[i], "attributes", 0);
                }
                break;
        case 5:
                for (i = 0; i < count; i++) {
-                       info[i].info5.printername       = samdb_result_string(msgs[i], "name", "");
+                       info[i].info5.printername       = ldb_msg_find_attr_as_string(msgs[i], "name", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info5.printername);
 
-                       info[i].info5.portname          = samdb_result_string(msgs[i], "port", "");
+                       info[i].info5.portname          = ldb_msg_find_attr_as_string(msgs[i], "port", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info5.portname);
 
-                       info[i].info5.attributes        = samdb_result_uint(msgs[i], "attributes", 0);
-                       info[i].info5.device_not_selected_timeout = samdb_result_uint(msgs[i], "device_not_selected_timeout", 0);
-                       info[i].info5.transmission_retry_timeout  = samdb_result_uint(msgs[i], "transmission_retry_timeout", 0);
+                       info[i].info5.attributes        = ldb_msg_find_attr_as_uint(msgs[i], "attributes", 0);
+                       info[i].info5.device_not_selected_timeout = ldb_msg_find_attr_as_uint(msgs[i], "device_not_selected_timeout", 0);
+                       info[i].info5.transmission_retry_timeout  = ldb_msg_find_attr_as_uint(msgs[i], "transmission_retry_timeout", 0);
                }
                break;
        default:
                return WERR_UNKNOWN_LEVEL;
        }
 
-       r->out.info     = info;
-       r->out.count    = count;
+       *r->out.info    = info;
+       *r->out.count   = count;
        return WERR_OK;
 }
 
@@ -612,31 +663,31 @@ static WERROR sptr_EnumPorts(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
        switch (r->in.level) {
        case 1:
                for (i = 0; i < count; i++) {
-                       info[i].info1.port_name         = samdb_result_string(msgs[i], "port_name", "");
+                       info[i].info1.port_name         = ldb_msg_find_attr_as_string(msgs[i], "port-name", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info1.port_name);
                }
                break;
        case 2:
                for (i=0; i < count; i++) {
-                       info[i].info2.port_name         = samdb_result_string(msgs[i], "port_name", "");
+                       info[i].info2.port_name         = ldb_msg_find_attr_as_string(msgs[i], "port-name", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.port_name);
 
-                       info[i].info2.monitor_name      = samdb_result_string(msgs[i], "monitor_name", "");
+                       info[i].info2.monitor_name      = ldb_msg_find_attr_as_string(msgs[i], "monitor-name", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
 
-                       info[i].info2.description       = samdb_result_string(msgs[i], "description", "");
+                       info[i].info2.description       = ldb_msg_find_attr_as_string(msgs[i], "description", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.description);
 
-                       info[i].info2.port_type         = samdb_result_uint(msgs[i], "port_type", SPOOLSS_PORT_TYPE_WRITE);
-                       info[i].info2.reserved          = samdb_result_uint(msgs[i], "reserved", 0);
+                       info[i].info2.port_type         = ldb_msg_find_attr_as_uint(msgs[i], "port-type", SPOOLSS_PORT_TYPE_WRITE);
+                       info[i].info2.reserved          = ldb_msg_find_attr_as_uint(msgs[i], "reserved", 0);
                }
                break;
        default:
                return WERR_UNKNOWN_LEVEL;
        }
 
-       r->out.info     = info;
-       r->out.count    = count;
+       *r->out.info    = info;
+       *r->out.count   = count;
        return WERR_OK;
 }
 
@@ -662,19 +713,19 @@ static WERROR sptr_EnumMonitors(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx
        switch (r->in.level) {
        case 1:
                for (i = 0; i < count; i++) {
-                       info[i].info1.monitor_name      = samdb_result_string(msgs[i], "monitor_name", "");
+                       info[i].info1.monitor_name      = ldb_msg_find_attr_as_string(msgs[i], "monitor-name", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info1.monitor_name);
                }
                break;
        case 2:
                for (i=0; i < count; i++) {
-                       info[i].info2.monitor_name      = samdb_result_string(msgs[i], "monitor_name", "");
+                       info[i].info2.monitor_name      = ldb_msg_find_attr_as_string(msgs[i], "monitor-name", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
 
-                       info[i].info2.environment       = samdb_result_string(msgs[i], "environment", "");
+                       info[i].info2.environment       = ldb_msg_find_attr_as_string(msgs[i], "environment", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.environment);
 
-                       info[i].info2.dll_name          = samdb_result_string(msgs[i], "dll_name", "");
+                       info[i].info2.dll_name          = ldb_msg_find_attr_as_string(msgs[i], "dll-name", "");
                        W_ERROR_HAVE_NO_MEMORY(info[i].info2.dll_name);
                }
                break;
@@ -682,12 +733,106 @@ static WERROR sptr_EnumMonitors(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx
                return WERR_UNKNOWN_LEVEL;
        }
 
+       *r->out.info    = info;
+       *r->out.count   = count;
+       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;
+       struct ldb_dn *base_dn;
+       int count;
+       union spoolss_FormInfo *info;
+
+       /* TODO: do checks access here
+        * if (!(printer->access_mask & desired_access)) {
+        *      return WERR_FOOBAR;
+        * }
+        */
+
+       base_dn = ldb_dn_new_fmt(mem_ctx, sptr_db, "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       = ldb_msg_find_attr_as_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
+
+               info->info1.form_name   = ldb_msg_find_attr_as_string(msgs[0], "form-name", NULL);
+               W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
+
+               info->info1.size.width  = ldb_msg_find_attr_as_uint(msgs[0], "size-width", 0);
+               info->info1.size.height = ldb_msg_find_attr_as_uint(msgs[0], "size-height", 0);
+
+               info->info1.area.left   = ldb_msg_find_attr_as_uint(msgs[0], "area-left", 0);
+               info->info1.area.top    = ldb_msg_find_attr_as_uint(msgs[0], "area-top", 0);
+               info->info1.area.right  = ldb_msg_find_attr_as_uint(msgs[0], "area-right", 0);
+               info->info1.area.bottom = ldb_msg_find_attr_as_uint(msgs[0], "area-bottom", 0);
+               break;
+       default:
+               return WERR_UNKNOWN_LEVEL;
+       }
+
        r->out.info     = info;
-       r->out.count    = count;
        return WERR_OK;
+}
+
+static WERROR sptr_GetPrintProcessorDirectory(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
+                                             struct spoolss_GetPrintProcessorDirectory *r)
+{
+       union spoolss_PrintProcessorDirectoryInfo *info;
+       const char *prefix;
+       const char *postfix;
+
+       /*
+        * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
+        *        are ignoring the r->in.level completely, so we do :-)
+        */
+
+       /*
+        * TODO: check the server name is ours
+        * - if it's a invalid UNC then return WERR_INVALID_NAME
+        * - if it's the wrong host name return WERR_INVALID_PARAM
+        * - if it's "" then we need to return a local WINDOWS path
+        */
+       if (!r->in.server || !r->in.server[0]) {
+               prefix = "C:\\PRTPROCS";
+       } else {
+               prefix = talloc_asprintf(mem_ctx, "%s\\prnproc$", r->in.server);
+               W_ERROR_HAVE_NO_MEMORY(prefix);
+       }
+
+       if (r->in.environment && strcmp(SPOOLSS_ARCHITECTURE_NT_X86, r->in.environment) == 0) {
+               postfix = "W32X86";
+       } else {
+               return WERR_INVALID_ENVIRONMENT;
+       }
+
+       info = talloc(mem_ctx, union spoolss_PrintProcessorDirectoryInfo);
+       W_ERROR_HAVE_NO_MEMORY(info);
+
+       info->info1.directory_name      = talloc_asprintf(mem_ctx, "%s\\%s", prefix, postfix);
+       W_ERROR_HAVE_NO_MEMORY(info->info1.directory_name);
+
+       r->out.info = info;
        return WERR_OK;
 }
 
+
 /*
   initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
  */
@@ -697,7 +842,8 @@ static const struct ntptr_ops ntptr_simple_ldb_ops = {
 
        /* PrintServer functions */
        .OpenPrintServer                = sptr_OpenPrintServer,
-
+/*     .XcvDataPrintServer             = sptr_XcvDataPrintServer,
+*/
        /* PrintServer PrinterData functions */
 /*     .EnumPrintServerData            = sptr_EnumPrintServerData,
 */     .GetPrintServerData             = sptr_GetPrintServerData,
@@ -707,7 +853,6 @@ static const struct ntptr_ops ntptr_simple_ldb_ops = {
        /* PrintServer Form functions */
        .EnumPrintServerForms           = sptr_EnumPrintServerForms,
        .AddPrintServerForm             = sptr_AddPrintServerForm,
-       .GetPrintServerForm             = sptr_GetPrintServerForm,
        .SetPrintServerForm             = sptr_SetPrintServerForm,
        .DeletePrintServerForm          = sptr_DeletePrintServerForm,
 
@@ -720,14 +865,18 @@ static const struct ntptr_ops ntptr_simple_ldb_ops = {
        /* Port functions */
        .EnumPorts                      = sptr_EnumPorts,
 /*     .OpenPort                       = sptr_OpenPort,
+       .XcvDataPort                    = sptr_XcvDataPort,
 */
        /* Monitor functions */
        .EnumMonitors                   = sptr_EnumMonitors,
 /*     .OpenMonitor                    = sptr_OpenMonitor,
+       .XcvDataMonitor                 = sptr_XcvDataMonitor,
 */
        /* PrintProcessor functions */
 /*     .EnumPrintProcessors            = sptr_EnumPrintProcessors,
 */
+       .GetPrintProcessorDirectory     = sptr_GetPrintProcessorDirectory,
+
        /* Printer functions */
        .EnumPrinters                   = sptr_EnumPrinters,
        .OpenPrinter                    = sptr_OpenPrinter,
@@ -735,6 +884,7 @@ static const struct ntptr_ops ntptr_simple_ldb_ops = {
        .GetPrinter                     = sptr_GetPrinter,
        .SetPrinter                     = sptr_SetPrinter,
        .DeletePrinter                  = sptr_DeletePrinter,
+       .XcvDataPrinter                 = sptr_XcvDataPrinter,
 */
        /* Printer Driver functions */
 /*     .GetPrinterDriver               = sptr_GetPrinterDriver,
@@ -748,8 +898,8 @@ static const struct ntptr_ops ntptr_simple_ldb_ops = {
        /* 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 */