r24667: Finally merge the registry improvements that Wilco Baan Hofman and I have
[sfrench/samba-autobuild/.git] / source4 / lib / registry / samba.c
similarity index 57%
rename from source4/lib/registry/reg_samba.c
rename to source4/lib/registry/samba.c
index 560e1ded31c6769a63d9dd15db27fb35aca5bf8c..244c467a2cd4ee1e5966182a0281694cad295ee9 100644 (file)
@@ -1,6 +1,6 @@
 /* 
    Unix SMB/CIFS implementation.
-   Copyright (C) Jelmer Vernooij                       2004.
+   Copyright (C) Jelmer Vernooij                       2004-2007.
 
    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
  * @brief Samba-specific registry functions
  */
 
-static WERROR reg_samba_get_predef (struct registry_context *ctx, uint32_t hkey, struct registry_key **k)
+WERROR mount_samba_hive(struct registry_context *ctx,
+                                               struct auth_session_info *auth_info,
+                                               struct cli_credentials *creds,
+                                               const char *name, 
+                                               uint32_t hive_id)
 {
        WERROR error;
-       const char *conf;
-       char *backend;
+       struct hive_key *hive;
        const char *location;
-       const char *hivename = reg_get_predef_name(hkey);
 
-       *k = NULL;
+       location = talloc_asprintf(ctx, "%s/%s.ldb", lp_private_dir(), name);
 
-       conf = lp_parm_string(-1, "registry", hivename);
-       
-       if (!conf) {
-               return WERR_NOT_SUPPORTED;
-       }
+       error = reg_open_hive(ctx, location, auth_info, creds, &hive);
+       if (!W_ERROR_IS_OK(error))
+               return error;
+
+       return reg_mount_hive(ctx, hive, hive_id, NULL);
+}
+
+
+_PUBLIC_ WERROR reg_open_samba (TALLOC_CTX *mem_ctx, 
+                               struct registry_context **ctx, 
+                               struct auth_session_info *session_info, 
+                               struct cli_credentials *credentials)
+{
+       WERROR result;
 
-       location = strchr(conf, ':');
-       if (location) {
-               backend = talloc_strndup(ctx, conf, (int)(location - conf));
-               location++;
-       } else {
-               backend = talloc_strdup(ctx, "ldb");
-               location = conf;
+       result = reg_open_local(mem_ctx, ctx, session_info, credentials);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
        }
 
+       mount_samba_hive(*ctx, session_info, credentials, 
+                                        "hklm", HKEY_LOCAL_MACHINE);
+
+       mount_samba_hive(*ctx, session_info, credentials, 
+                                        "hkcr", HKEY_CLASSES_ROOT);
+
+       /* FIXME: Should be mounted from NTUSER.DAT in the home directory of the 
+        * current user */
+       mount_samba_hive(*ctx, session_info, credentials, 
+                                        "hkcu", HKEY_CURRENT_USER);
+
+       mount_samba_hive(*ctx, session_info, credentials, 
+                                        "hku", HKEY_USERS);
+
        /* FIXME: Different hive backend for HKEY_CLASSES_ROOT: merged view of HKEY_LOCAL_MACHINE\Software\Classes
         * and HKEY_CURRENT_USER\Software\Classes */
 
@@ -59,23 +80,6 @@ static WERROR reg_samba_get_predef (struct registry_context *ctx, uint32_t hkey,
        /* FIXME: HKEY_LOCAL_MACHINE\Hardware is autogenerated */
 
        /* FIXME: HKEY_LOCAL_MACHINE\Security\SAM is an alias for HKEY_LOCAL_MACHINE\SAM */
-
-       error = reg_open_hive(ctx, backend, location, ctx->session_info, ctx->credentials, k);
-
-       talloc_free(backend);
-
-       return error;
-}
-
-_PUBLIC_ WERROR reg_open_local (TALLOC_CTX *mem_ctx, 
-                               struct registry_context **ctx, 
-                               struct auth_session_info *session_info, 
-                               struct cli_credentials *credentials)
-{
-       *ctx = talloc(mem_ctx, struct registry_context);
-       (*ctx)->credentials = talloc_reference(*ctx, credentials);
-       (*ctx)->session_info = talloc_reference(*ctx, session_info);
-       (*ctx)->get_predefined_key = reg_samba_get_predef;
        
        return WERR_OK;
 }