summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2011-08-10 14:25:56 -0400
committerSimo Sorce <idra@samba.org>2011-08-21 09:05:02 -0400
commit9738ee40158e9e368f8fcf7db3294c408750dab0 (patch)
treef494b9b2176399924651561fb55609279c512a65
parent7b715f15b198def34278eec558ff9cf29bb28a6d (diff)
downloadsamba-9738ee40158e9e368f8fcf7db3294c408750dab0.tar.gz
samba-9738ee40158e9e368f8fcf7db3294c408750dab0.tar.bz2
samba-9738ee40158e9e368f8fcf7db3294c408750dab0.zip
s3-rpc_server: Reduce code duplication
Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Simo Sorce <idra@samba.org>
-rw-r--r--source3/rpc_server/rpc_service_setup.c121
-rw-r--r--source3/rpc_server/rpc_service_setup.h22
2 files changed, 38 insertions, 105 deletions
diff --git a/source3/rpc_server/rpc_service_setup.c b/source3/rpc_server/rpc_service_setup.c
index cd968c5497..0600262543 100644
--- a/source3/rpc_server/rpc_service_setup.c
+++ b/source3/rpc_server/rpc_service_setup.c
@@ -52,42 +52,46 @@
#include "rpc_server/rpc_server.h"
#include "rpc_server/epmapper/srv_epmapper.h"
-enum rpc_service_mode_e rpc_epmapper_mode(void)
+/* the default is "embedded" so this table
+ * lists only services that are not using
+ * the default in order to keep enumerating it
+ * in rpc_service_mode() as short as possible
+ */
+struct rpc_service_defaults {
+ const char *name;
+ const char *def_mode;
+} rpc_service_defaults[] = {
+ { "epmapper", "external" },
+ /* { "spoolss", "embedded" }, */
+ /* { "lsarpc", "embedded" }, */
+ /* { "samr", "embedded" }, */
+ /* { "netlogon", "embedded" }, */
+
+ { NULL, NULL }
+};
+
+enum rpc_service_mode_e rpc_service_mode(const char *name)
{
const char *rpcsrv_type;
enum rpc_service_mode_e state;
+ const char *def;
+ int i;
- rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
- "rpc_server",
- "epmapper",
- "daemon");
-
- if (strcasecmp_m(rpcsrv_type, "external") == 0) {
- state = RPC_SERVICE_MODE_EXTERNAL;
- } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0) {
- state = RPC_SERVICE_MODE_DAEMON;
- } else {
- state = RPC_SERVICE_MODE_DISABLED;
+ def = "embedded";
+ for (i = 0; rpc_service_defaults[i].name; i++) {
+ if (strcasecmp_m(name, rpc_service_defaults[i].name) == 0) {
+ def = rpc_service_defaults[i].def_mode;
+ }
}
- return state;
-}
-
-enum rpc_service_mode_e rpc_spoolss_mode(void)
-{
- const char *rpcsrv_type;
- enum rpc_service_mode_e state;
-
rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
- "rpc_server",
- "spoolss",
- "embedded");
+ "rpc_server", name, def);
if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
state = RPC_SERVICE_MODE_EMBEDDED;
} else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
state = RPC_SERVICE_MODE_EXTERNAL;
- } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0) {
+ } else if (strcasecmp(rpcsrv_type, "daemon") == 0) {
state = RPC_SERVICE_MODE_DAEMON;
} else {
state = RPC_SERVICE_MODE_DISABLED;
@@ -96,75 +100,6 @@ enum rpc_service_mode_e rpc_spoolss_mode(void)
return state;
}
-enum rpc_service_mode_e rpc_lsarpc_mode(void)
-{
- const char *rpcsrv_type;
- enum rpc_service_mode_e mode;
-
- rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
- "rpc_server",
- "lsarpc",
- "embedded");
-
- if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
- mode = RPC_SERVICE_MODE_EMBEDDED;
- } else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
- mode = RPC_SERVICE_MODE_EXTERNAL;
- } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0) {
- mode = RPC_SERVICE_MODE_DAEMON;
- } else {
- mode = RPC_SERVICE_MODE_DISABLED;
- }
-
- return mode;
-}
-
-enum rpc_service_mode_e rpc_samr_mode(void)
-{
- const char *rpcsrv_type;
- enum rpc_service_mode_e mode;
-
- rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
- "rpc_server",
- "samr",
- "embedded");
-
- if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
- mode = RPC_SERVICE_MODE_EMBEDDED;
- } else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
- mode = RPC_SERVICE_MODE_EXTERNAL;
- } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0) {
- mode = RPC_SERVICE_MODE_DAEMON;
- } else {
- mode = RPC_SERVICE_MODE_DISABLED;
- }
-
- return mode;
-}
-
-enum rpc_service_mode_e rpc_netlogon_mode(void)
-{
- const char *rpcsrv_type;
- enum rpc_service_mode_e mode;
-
- rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
- "rpc_server",
- "netlogon",
- "embedded");
-
- if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
- mode = RPC_SERVICE_MODE_EMBEDDED;
- } else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
- mode = RPC_SERVICE_MODE_EXTERNAL;
- } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0) {
- mode = RPC_SERVICE_MODE_DAEMON;
- } else {
- mode = RPC_SERVICE_MODE_DISABLED;
- }
-
- return mode;
-}
-
static bool rpc_setup_epmapper(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx)
{
diff --git a/source3/rpc_server/rpc_service_setup.h b/source3/rpc_server/rpc_service_setup.h
index aef347bdcd..908c0e48b8 100644
--- a/source3/rpc_server/rpc_service_setup.h
+++ b/source3/rpc_server/rpc_service_setup.h
@@ -32,22 +32,20 @@ enum rpc_service_mode_e {
};
/**
- * @brief Get the mode in which epmapper is started.
+ * @brief Get the mode in which a service is started.
*
- * @return The mode.
- */
-enum rpc_service_mode_e rpc_epmapper_mode(void);
-
-/**
- * @brief Get the mode in which epmapper is started.
+ * @param name Name of the service
+ * @param def_mode The default mode for the service
*
- * @return The mode.
+ * @return The actual configured mode.
*/
-enum rpc_service_mode_e rpc_spoolss_mode(void);
+enum rpc_service_mode_e rpc_service_mode(const char *name);
-enum rpc_service_mode_e rpc_lsarpc_mode(void);
-enum rpc_service_mode_e rpc_samr_mode(void);
-enum rpc_service_mode_e rpc_netlogon_mode(void);
+#define rpc_epmapper_mode() rpc_service_mode("epmapper")
+#define rpc_spoolss_mode() rpc_service_mode("spoolss")
+#define rpc_lsarpc_mode() rpc_service_mode("lsarpc")
+#define rpc_samr_mode() rpc_service_mode("samr")
+#define rpc_netlogon_mode() rpc_service_mode("netlogon")
/**
* @brief Register an endpoint at the endpoint mapper.