r9022: One more step in the game of whack-a-mole with the PAC.
[Samba/gbeck.git] / source4 / ntptr / ntptr_base.c
blobf12a58cb4ec6daec50fd90d4812975580f358ae5
1 /*
2 Unix SMB/CIFS implementation.
4 NTPTR base code
6 Copyright (C) Stefan (metze) Metzmacher 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 this implements the core code for all NTPTR modules. Backends register themselves here.
26 #include "includes.h"
27 #include "ntptr/ntptr.h"
28 #include "dlinklist.h"
30 /* the list of currently registered NTPTR backends */
31 static struct ntptr_backend {
32 const struct ntptr_ops *ops;
33 } *backends = NULL;
34 static int num_backends;
37 register a NTPTR backend.
39 The 'name' can be later used by other backends to find the operations
40 structure for this backend.
42 NTSTATUS ntptr_register(const void *_ops)
44 const struct ntptr_ops *ops = _ops;
45 struct ntptr_ops *new_ops;
47 if (ntptr_backend_byname(ops->name) != NULL) {
48 /* its already registered! */
49 DEBUG(0,("NTPTR backend '%s' already registered\n",
50 ops->name));
51 return NT_STATUS_OBJECT_NAME_COLLISION;
54 backends = realloc_p(backends, struct ntptr_backend, num_backends+1);
55 if (!backends) {
56 smb_panic("out of memory in ntptr_register");
59 new_ops = smb_xmemdup(ops, sizeof(*ops));
60 new_ops->name = smb_xstrdup(ops->name);
62 backends[num_backends].ops = new_ops;
64 num_backends++;
66 DEBUG(3,("NTPTR backend '%s'\n",
67 ops->name));
69 return NT_STATUS_OK;
74 return the operations structure for a named backend
76 const struct ntptr_ops *ntptr_backend_byname(const char *name)
78 int i;
80 for (i=0;i<num_backends;i++) {
81 if (strcmp(backends[i].ops->name, name) == 0) {
82 return backends[i].ops;
86 return NULL;
91 return the NTPTR interface version, and the size of some critical types
92 This can be used by backends to either detect compilation errors, or provide
93 multiple implementations for different smbd compilation options in one module
95 static const struct ntptr_critical_sizes critical_sizes = {
96 .interface_version = NTPTR_INTERFACE_VERSION,
97 .sizeof_ntptr_critical_sizes = sizeof(struct ntptr_critical_sizes),
98 .sizeof_ntptr_context = sizeof(struct ntptr_context),
99 .sizeof_ntptr_ops = sizeof(struct ntptr_ops),
101 const struct ntptr_critical_sizes *ntptr_interface_version(void)
103 return &critical_sizes;
107 create a ntptr_context with a specified NTPTR backend
109 NTSTATUS ntptr_init_context(TALLOC_CTX *mem_ctx, const char *providor, struct ntptr_context **_ntptr)
111 NTSTATUS status;
112 struct ntptr_context *ntptr;
114 if (!providor) {
115 return NT_STATUS_INTERNAL_ERROR;
118 ntptr = talloc(mem_ctx, struct ntptr_context);
119 NT_STATUS_HAVE_NO_MEMORY(ntptr);
120 ntptr->private_data = NULL;
121 ntptr->ops = ntptr_backend_byname(providor);
123 if (!ntptr->ops) {
124 DEBUG(1,("ntptr_init_context: failed to find NTPTR providor='%s'\n",
125 providor));
126 return NT_STATUS_INTERNAL_ERROR;
129 status = ntptr->ops->init_context(ntptr);
130 NT_STATUS_NOT_OK_RETURN(status);
132 *_ntptr = ntptr;
133 return NT_STATUS_OK;