3ddc18935db7f50012eed0c9fce48591ccce8332
[mat/samba.git] / source3 / rpc_server / rpc_config.c
1 /*
2    Unix SMB/Netbios implementation.
3    Generic infrstructure for RPC Daemons
4    Copyright (C) Simo Sorce 2011
5    Copyright (C) Andreas Schneider 2011
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "rpc_server/rpc_config.h"
23
24 /* the default is "embedded" so this table
25  * lists only services that are not using
26  * the default in order to keep enumerating it
27  * in rpc_service_mode() as short as possible
28  */
29 struct rpc_service_defaults {
30         const char *name;
31         const char *def_mode;
32 } rpc_service_defaults[] = {
33         { "epmapper", "disabled" },
34         /* { "spoolss", "embedded" }, */
35         /* { "lsarpc", "embedded" }, */
36         /* { "samr", "embedded" }, */
37         /* { "netlogon", "embedded" }, */
38
39         { NULL, NULL }
40 };
41
42 enum rpc_service_mode_e rpc_service_mode(const char *name)
43 {
44         const char *pipe_name = name;
45         const char *rpcsrv_type;
46         enum rpc_service_mode_e state;
47         const char *def;
48         int i;
49
50         /* Handle pipes with multiple names */
51         if (strcmp(pipe_name, "lsass") == 0) {
52                 pipe_name = "lsarpc";
53         } else if (strcmp(pipe_name, "plugplay") == 0) {
54                 pipe_name = "ntsvcs";
55         }
56
57         def = "embedded";
58         for (i = 0; rpc_service_defaults[i].name; i++) {
59                 if (strcasecmp_m(pipe_name, rpc_service_defaults[i].name) == 0) {
60                         def = rpc_service_defaults[i].def_mode;
61                 }
62         }
63
64         rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
65                                            "rpc_server", pipe_name, def);
66
67         if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
68                 state = RPC_SERVICE_MODE_EMBEDDED;
69         } else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
70                 state = RPC_SERVICE_MODE_EXTERNAL;
71         } else {
72                 state = RPC_SERVICE_MODE_DISABLED;
73         }
74
75         return state;
76 }
77
78
79 /* the default is "embedded" so this table
80  * lists only daemons that are not using
81  * the default in order to keep enumerating it
82  * in rpc_daemon_type() as short as possible
83  */
84 struct rpc_daemon_defaults {
85         const char *name;
86         const char *def_type;
87 } rpc_daemon_defaults[] = {
88         { "epmd", "disabled" },
89         /* { "spoolssd", "embedded" }, */
90         /* { "lsasd", "embedded" }, */
91
92         { NULL, NULL }
93 };
94
95 enum rpc_daemon_type_e rpc_daemon_type(const char *name)
96 {
97         const char *rpcsrv_type;
98         enum rpc_daemon_type_e type;
99         const char *def;
100         int i;
101
102         def = "embedded";
103         for (i = 0; rpc_daemon_defaults[i].name; i++) {
104                 if (strcasecmp_m(name, rpc_daemon_defaults[i].name) == 0) {
105                         def = rpc_daemon_defaults[i].def_type;
106                 }
107         }
108
109         rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
110                                            "rpc_daemon", name, def);
111
112         if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
113                 type = RPC_DAEMON_EMBEDDED;
114         } else if (strcasecmp_m(rpcsrv_type, "fork") == 0) {
115                 type = RPC_DAEMON_FORK;
116         } else {
117                 type = RPC_DAEMON_DISABLED;
118         }
119
120         return type;
121 }