This patch adds a better dcerpc server infastructure.
[sfrench/samba-autobuild/.git] / source / ntvfs / ntvfs_base.c
index 57cdb97e9f5e783d97ebcba38d5aff181aef6060..e4009fd1f0144ca6ffc33450aa402bb7ce73aa80 100644 (file)
@@ -1,7 +1,9 @@
 /* 
    Unix SMB/CIFS implementation.
    NTVFS base code
+
    Copyright (C) Andrew Tridgell 2003
+   Copyright (C) Stefan (metze) Metzmacher 2004
 
    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
@@ -28,8 +30,6 @@
  * can be more than one backend with the same name, as long as they
  * have different typesx */
 static struct {
-       const char *name;
-       enum ntvfs_type type;
        struct ntvfs_ops *ops;
 } *backends = NULL;
 static int num_backends;
@@ -42,13 +42,15 @@ static int num_backends;
 
   The 'type' is used to specify whether this is for a disk, printer or IPC$ share
 */
-BOOL ntvfs_register(const char *name, enum ntvfs_type type, struct ntvfs_ops *ops)
+static NTSTATUS ntvfs_register(void *_ops)
 {
-       if (ntvfs_backend_byname(name, type) != NULL) {
+       struct ntvfs_ops *ops = _ops;
+       
+       if (ntvfs_backend_byname(ops->name, ops->type) != NULL) {
                /* its already registered! */
                DEBUG(2,("NTVFS backend '%s' for type %d already registered\n", 
-                        name, (int)type));
-               return False;
+                        ops->name, (int)ops->type));
+               return NT_STATUS_OBJECT_NAME_COLLISION;
        }
 
        backends = Realloc(backends, sizeof(backends[0]) * (num_backends+1));
@@ -56,13 +58,12 @@ BOOL ntvfs_register(const char *name, enum ntvfs_type type, struct ntvfs_ops *op
                smb_panic("out of memory in ntvfs_register");
        }
 
-       backends[num_backends].name = smb_xstrdup(name);
-       backends[num_backends].type = type;
        backends[num_backends].ops = smb_xmemdup(ops, sizeof(*ops));
+       backends[num_backends].ops->name = smb_xstrdup(ops->name);
 
        num_backends++;
 
-       return True;
+       return NT_STATUS_OK;
 }
 
 
@@ -74,8 +75,8 @@ struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntvfs_type type)
        int i;
 
        for (i=0;i<num_backends;i++) {
-               if (backends[i].type == type && 
-                   strcmp(backends[i].name, name) == 0) {
+               if (backends[i].ops->type == type && 
+                   strcmp(backends[i].ops->name, name) == 0) {
                        return backends[i].ops;
                }
        }
@@ -89,14 +90,17 @@ struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntvfs_type type)
   This can be used by backends to either detect compilation errors, or provide
   multiple implementations for different smbd compilation options in one module
 */
-int ntvfs_interface_version(struct ntvfs_critical_sizes *sizes)
+const struct ntvfs_critical_sizes *ntvfs_interface_version(void)
 {
-       sizes->sizeof_ntvfs_ops = sizeof(struct ntvfs_ops);
-       sizes->sizeof_SMB_OFF_T = sizeof(SMB_OFF_T);
-       sizes->sizeof_tcon_context = sizeof(struct tcon_context);
-       sizes->sizeof_request_context = sizeof(struct request_context);
-
-       return NTVFS_INTERFACE_VERSION;
+       static const struct ntvfs_critical_sizes critical_sizes = {
+               NTVFS_INTERFACE_VERSION,
+               sizeof(struct ntvfs_ops),
+               sizeof(SMB_OFF_T),
+               sizeof(struct tcon_context),
+               sizeof(struct request_context),
+       };
+
+       return &critical_sizes;
 }
 
 
@@ -105,21 +109,17 @@ int ntvfs_interface_version(struct ntvfs_critical_sizes *sizes)
 */
 BOOL ntvfs_init(void)
 {
-       /* initialise our 3 basic backends. These are assumed to be
-        * present and are always built in */
-       if (!posix_vfs_init() ||
-           !ipc_vfs_init() ||
-           !print_vfs_init()) {
+       NTSTATUS status;
+
+       status = register_subsystem("ntvfs", ntvfs_register); 
+       if (!NT_STATUS_IS_OK(status)) {
                return False;
        }
-       /* initialize optional backends, e.g. CIFS. We allow failures here. */
-       cifs_vfs_init();
 
-#if WITH_NTVFS_STFS
-       tank_vfs_init();
-#endif
+       /* FIXME: Perhaps panic if a basic backend, such as IPC, fails to initialise? */
+       static_init_ntvfs;
 
-       DEBUG(3,("NTVFS version %d initialised\n", NTVFS_INTERFACE_VERSION));
+       DEBUG(3,("NTVFS subsystem version %d initialised\n", NTVFS_INTERFACE_VERSION));
        return True;
 }