summaryrefslogtreecommitdiff
path: root/source4/param/share.c
blob: 4b747f85aef9bb381ee4b7da3c319d5744f6641f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* 
   Unix SMB/CIFS implementation.
   
   Modular services configuration system
   
   Copyright (C) Simo Sorce	2006
   
   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 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   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, see <http://www.gnu.org/licenses/>.
*/

#include "includes.h"
#include "param/share.h"
#include "build.h"
#include "param/param.h"

const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
{
	return scfg->ctx->ops->string_option(scfg, opt_name, defval);
}

int share_int_option(struct share_config *scfg, const char *opt_name, int defval)
{
	return scfg->ctx->ops->int_option(scfg, opt_name, defval);
}

bool share_bool_option(struct share_config *scfg, const char *opt_name, bool defval)
{
	return scfg->ctx->ops->bool_option(scfg, opt_name, defval);
}

const char **share_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
{
	return scfg->ctx->ops->string_list_option(mem_ctx, scfg, opt_name);
}

NTSTATUS share_list_all(TALLOC_CTX *mem_ctx, struct share_context *sctx, int *count, const char ***names)
{
	return sctx->ops->list_all(mem_ctx, sctx, count, names);
}

NTSTATUS share_get_config(TALLOC_CTX *mem_ctx, struct share_context *sctx, const char *name, struct share_config **scfg)
{
	return sctx->ops->get_config(mem_ctx, sctx, name, scfg);
}

NTSTATUS share_create(struct share_context *sctx, const char *name, struct share_info *info, int count)
{
	if (sctx->ops->create) {
		return sctx->ops->create(sctx, name, info, count);
	}
	return NT_STATUS_NOT_IMPLEMENTED;
}

NTSTATUS share_set(struct share_context *sctx, const char *name, struct share_info *info, int count)
{
	if (sctx->ops->set) {
		return sctx->ops->set(sctx, name, info, count);
	}
	return NT_STATUS_NOT_IMPLEMENTED;
}

NTSTATUS share_remove(struct share_context *sctx, const char *name)
{
	if (sctx->ops->remove) {
		return sctx->ops->remove(sctx, name);
	}
	return NT_STATUS_NOT_IMPLEMENTED;
}

/* List of currently available share backends */
static struct share_ops **backends = NULL;

static const struct share_ops *share_backend_by_name(const char *name)
{
	int i;

	for (i = 0; backends && backends[i]; i++) {
		if (strcmp(backends[i]->name, name) == 0) {
			return backends[i];
		}
	}

	return NULL;
}

/*
  Register the share backend
*/
NTSTATUS share_register(const struct share_ops *ops)
{
	int i;

	if (share_backend_by_name(ops->name) != NULL) {
		DEBUG(0,("SHARE backend [%s] already registered\n", ops->name));
		return NT_STATUS_OBJECT_NAME_COLLISION;
	}

	i = 0;
	while (backends && backends[i]) {
		i++;
	}

	backends = realloc_p(backends, struct share_ops *, i + 2);
	if (!backends) {
		smb_panic("out of memory in share_register");
	}

	backends[i] = (struct share_ops *)smb_xmemdup(ops, sizeof(*ops));
	backends[i]->name = smb_xstrdup(ops->name);

	backends[i + 1] = NULL;

	DEBUG(3, ("SHARE backend [%s] registered.\n", ops->name));

	return NT_STATUS_OK;
}

NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, const char *backend_name,
				   struct share_context **ctx)
{
	const struct share_ops *ops;

	ops = share_backend_by_name(backend_name);
	if (!ops) {
		DEBUG(0, ("share_init_connection: share backend [%s] not found!\n", backend_name));
		return NT_STATUS_INTERNAL_ERROR;
	}

	return ops->init(mem_ctx, ops, ctx);
}

/*
  initialise the SHARE subsystem
*/
NTSTATUS share_init(void)
{
	init_module_fn static_init[] = STATIC_share_MODULES;

	run_init_functions(static_init);

	return NT_STATUS_OK;
}