示例#1
0
文件: mit_samba.c 项目: GSam/samba
int mit_samba_context_init(struct mit_samba_context **_ctx)
{
	NTSTATUS status;
	struct mit_samba_context *ctx;
	const char *s4_conf_file;
	int ret;
	struct samba_kdc_base_context base_ctx;

	ctx = talloc_zero(NULL, struct mit_samba_context);
	if (!ctx) {
		ret = ENOMEM;
		goto done;
	}

	base_ctx.ev_ctx = tevent_context_init(ctx);
	if (!base_ctx.ev_ctx) {
		ret = ENOMEM;
		goto done;
	}
	tevent_loop_allow_nesting(base_ctx.ev_ctx);
	base_ctx.lp_ctx = loadparm_init_global(false);
	if (!base_ctx.lp_ctx) {
		ret = ENOMEM;
		goto done;
	}

	setup_logging("mitkdc", DEBUG_STDOUT);

	/* init s4 configuration */
	s4_conf_file = lpcfg_configfile(base_ctx.lp_ctx);
	if (s4_conf_file) {
		lpcfg_load(base_ctx.lp_ctx, s4_conf_file);
	} else {
		lpcfg_load_default(base_ctx.lp_ctx);
	}

	status = samba_kdc_setup_db_ctx(ctx, &base_ctx, &ctx->db_ctx);
	if (!NT_STATUS_IS_OK(status)) {
		ret = EINVAL;
		goto done;
	}

	/* init heimdal's krb_context and log facilities */
	ret = smb_krb5_init_context_basic(ctx,
					  ctx->db_ctx->lp_ctx,
					  &ctx->context);
	if (ret) {
		goto done;
	}

	ret = 0;

done:
	if (ret) {
		mit_samba_context_free(ctx);
	} else {
		*_ctx = ctx;
	}
	return ret;
}
示例#2
0
文件: pyparam.c 项目: Arkhont/samba
static PyObject *py_lp_ctx_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
	py_talloc_Object *ret = (py_talloc_Object *)type->tp_alloc(type, 0);
	if (ret == NULL) {
		PyErr_NoMemory();
		return NULL;
	}
	ret->talloc_ctx = talloc_new(NULL);
	if (ret->talloc_ctx == NULL) {
		PyErr_NoMemory();
		return NULL;
	}
	ret->ptr = loadparm_init_global(false);
	if (ret->ptr == NULL) {
		PyErr_NoMemory();
		return NULL;
	}
	return (PyObject *)ret;
}
示例#3
0
/*
  called to initialise the driver
 */
_PUBLIC_ isc_result_t dlz_create(const char *dlzname,
				 unsigned int argc, char *argv[],
				 void **dbdata, ...)
{
	struct dlz_bind9_data *state;
	const char *helper_name;
	va_list ap;
	isc_result_t result;
	TALLOC_CTX *tmp_ctx;
	int ret;
	struct ldb_dn *dn;
	struct b9_options options;

	ZERO_STRUCT(options);

	state = talloc_zero(NULL, struct dlz_bind9_data);
	if (state == NULL) {
		return ISC_R_NOMEMORY;
	}

	tmp_ctx = talloc_new(state);

	/* fill in the helper functions */
	va_start(ap, dbdata);
	while ((helper_name = va_arg(ap, const char *)) != NULL) {
		b9_add_helper(state, helper_name, va_arg(ap, void*));
	}
	va_end(ap);

	state->ev_ctx = s4_event_context_init(state);
	if (state->ev_ctx == NULL) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	state->samdb = ldb_init(state, state->ev_ctx);
	if (state->samdb == NULL) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Failed to create ldb");
		result = ISC_R_FAILURE;
		goto failed;
	}

	result = parse_options(state, argc, argv, &options);
	if (result != ISC_R_SUCCESS) {
		goto failed;
	}

	state->lp = loadparm_init_global(true);
	if (state->lp == NULL) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	if (options.url == NULL) {
		options.url = talloc_asprintf(tmp_ctx, "ldapi://%s",
					      lpcfg_private_path(tmp_ctx, state->lp, "ldap_priv/ldapi"));
		if (options.url == NULL) {
			result = ISC_R_NOMEMORY;
			goto failed;
		}
	}

	ret = ldb_connect(state->samdb, options.url, 0, NULL);
	if (ret != LDB_SUCCESS) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Failed to connect to %s - %s",
			   options.url, ldb_errstring(state->samdb));
		result = ISC_R_FAILURE;
		goto failed;
	}

	ret = ldb_modules_hook(state->samdb, LDB_MODULE_HOOK_CMDLINE_POSTCONNECT);
	if (ret != LDB_SUCCESS) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Failed postconnect for %s - %s",
			   options.url, ldb_errstring(state->samdb));
		result = ISC_R_FAILURE;
		goto failed;
	}

	dn = ldb_get_default_basedn(state->samdb);
	if (dn == NULL) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Unable to get basedn for %s - %s",
			   options.url, ldb_errstring(state->samdb));
		result = ISC_R_FAILURE;
		goto failed;
	}

	state->log(ISC_LOG_INFO, "samba_dlz: started for DN %s",
		   ldb_dn_get_linearized(dn));

	*dbdata = state;

	talloc_free(tmp_ctx);
	return ISC_R_SUCCESS;

failed:
	talloc_free(state);
	return result;
}
示例#4
0
static void popt_samba_callback(poptContext con, 
			   enum poptCallbackReason reason,
			   const struct poptOption *opt,
			   const char *arg, const void *data)
{
	const char *pname;

	if (reason == POPT_CALLBACK_REASON_POST) {
		if (lpcfg_configfile(cmdline_lp_ctx) == NULL) {
			lpcfg_load_default(cmdline_lp_ctx);
		}
		/* Hook any 'every Samba program must do this, after
		 * the smb.conf is setup' functions here */
		return;
	}

	/* Find out basename of current program */
	pname = strrchr_m(poptGetInvocationName(con),'/');

	if (!pname)
		pname = poptGetInvocationName(con);
	else 
		pname++;

	if (reason == POPT_CALLBACK_REASON_PRE) {
		/* Hook for 'almost the first thing to do in a samba program' here */
		/* setup for panics */
		fault_setup();

		/* and logging */
		setup_logging(pname, DEBUG_DEFAULT_STDOUT);
		talloc_set_log_fn(popt_s4_talloc_log_fn);
		talloc_set_abort_fn(smb_panic);

		cmdline_lp_ctx = loadparm_init_global(false);
		return;
	}

	switch(opt->val) {

	case OPT_LEAK_REPORT:
		talloc_enable_leak_report();
		break;

	case OPT_LEAK_REPORT_FULL:
		talloc_enable_leak_report_full();
		break;

	case OPT_OPTION:
		if (!lpcfg_set_option(cmdline_lp_ctx, arg)) {
			fprintf(stderr, "Error setting option '%s'\n", arg);
			exit(1);
		}
		break;

	case 'd':
		lpcfg_set_cmdline(cmdline_lp_ctx, "log level", arg);
		break;

	case OPT_DEBUG_STDERR:
		setup_logging(pname, DEBUG_STDERR);
		break;

	case 's':
		if (arg) {
			lpcfg_load(cmdline_lp_ctx, arg);
		}
		break;

	case 'l':
		if (arg) {
			char *new_logfile = talloc_asprintf(NULL, "%s/log.%s", arg, pname);
			lpcfg_set_cmdline(cmdline_lp_ctx, "log file", new_logfile);
			talloc_free(new_logfile);
		}
		break;
	

	}

}
示例#5
0
int main(int argc, const char *argv[])
{
TALLOC_CTX			*mem_ctx;
int				retval;
struct mapistore_context		*mstore_ctx;
struct loadparm_context			*lp_ctx;
struct backend_context			*context;
struct backend_context_list *context_list;
poptContext			pc;
int				opt, i;
const char			*opt_debug = NULL;
uint32_t			context_id = 0;
void				*root_folder;

enum { OPT_DEBUG=1000 };

struct poptOption long_options[] = {
		POPT_AUTOHELP
		{ "debuglevel",	'd', POPT_ARG_STRING, NULL, OPT_DEBUG,	"set the debug level", NULL },
		{ NULL, 0, 0, NULL, 0, NULL, NULL }
	};

mem_ctx = talloc_named(NULL, 0, "mapistore_EL_test");
lp_ctx = loadparm_init_global(true);
setup_logging(NULL, DEBUG_STDOUT);
	
pc = poptGetContext("mapistore_test", argc, argv, long_options, 0);
while ((opt = poptGetNextOpt(pc)) != -1) 
  {
	switch (opt) 
	  {
		case OPT_DEBUG:
			opt_debug = poptGetOptArg(pc);
			break;
		}
	}

poptFreeContext(pc);

if (opt_debug) 
	lpcfg_set_cmdline(lp_ctx, "log level", opt_debug);
	
	
printf("Mapping path             : ");
retval = mapistore_set_mapping_path("/tmp");
if (retval != MAPISTORE_SUCCESS) 
  {
	printf("ERROR: %s\n", mapistore_errstr(retval));
	exit (1);
	}
printf("OK\n");

printf("Initialise mapistore\n");
mstore_ctx = mapistore_init(mem_ctx, lp_ctx, NULL);
if (!mstore_ctx) 
  {
	printf("ERROR: %s\n", mapistore_errstr(retval));
	exit (1);
	}

printf("Adding a context (INBOX)\n");
retval = mapistore_add_context(mstore_ctx, "Administrator", "EasyLinux://INBOX", -1, &context_id, &root_folder);
if (retval != MAPISTORE_SUCCESS) 
  {
	printf("ERROR: %s\n", mapistore_errstr(retval));
	exit (1);
	}
  //DEBUG(0,("    Root folder: %s",(char *)root_folder) );
/*

  DEBUG(0,("Delete context             : "));
	retval = mapistore_del_context(mstore_ctx, context_id);
	DEBUG(0,("OK\n"));
*/	
	DEBUG(0,("Release                     : "));
	retval = mapistore_release(mstore_ctx);
	if (retval != MAPISTORE_SUCCESS) {
		DEBUG(0, ("%s\n", mapistore_errstr(retval)));
		exit (1);
	}
	DEBUG(0,("OK\n"));

	return 0;
}
示例#6
0
文件: dlz_bind9.c 项目: sprymak/samba
/*
  called to initialise the driver
 */
_PUBLIC_ isc_result_t dlz_create(const char *dlzname,
				 unsigned int argc, char *argv[],
				 void **dbdata, ...)
{
	struct dlz_bind9_data *state;
	const char *helper_name;
	va_list ap;
	isc_result_t result;
	struct ldb_dn *dn;
	NTSTATUS nt_status;

	state = talloc_zero(NULL, struct dlz_bind9_data);
	if (state == NULL) {
		return ISC_R_NOMEMORY;
	}

	talloc_set_destructor(state, dlz_state_debug_unregister);

	/* fill in the helper functions */
	va_start(ap, dbdata);
	while ((helper_name = va_arg(ap, const char *)) != NULL) {
		b9_add_helper(state, helper_name, va_arg(ap, void*));
	}
	va_end(ap);

	/* Do not install samba signal handlers */
	fault_setup_disable();

	/* Start logging (to the bind9 logs) */
	debug_set_callback(state, b9_debug);

	state->ev_ctx = s4_event_context_init(state);
	if (state->ev_ctx == NULL) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	result = parse_options(state, argc, argv, &state->options);
	if (result != ISC_R_SUCCESS) {
		goto failed;
	}

	state->lp = loadparm_init_global(true);
	if (state->lp == NULL) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	if (state->options.debug) {
		lpcfg_do_global_parameter(state->lp, "log level", state->options.debug);
	} else {
		lpcfg_do_global_parameter(state->lp, "log level", "0");
	}

	if (smb_krb5_init_context(state, state->ev_ctx, state->lp, &state->smb_krb5_ctx) != 0) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	nt_status = gensec_init();
	if (!NT_STATUS_IS_OK(nt_status)) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	state->auth_context = talloc_zero(state, struct auth4_context);
	if (state->auth_context == NULL) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	if (state->options.url == NULL) {
		state->options.url = lpcfg_private_path(state, state->lp, "dns/sam.ldb");
		if (state->options.url == NULL) {
			result = ISC_R_NOMEMORY;
			goto failed;
		}
	}

	state->samdb = samdb_connect_url(state, state->ev_ctx, state->lp,
					system_session(state->lp), 0, state->options.url);
	if (state->samdb == NULL) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Failed to connect to %s",
			state->options.url);
		result = ISC_R_FAILURE;
		goto failed;
	}

	dn = ldb_get_default_basedn(state->samdb);
	if (dn == NULL) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Unable to get basedn for %s - %s",
			   state->options.url, ldb_errstring(state->samdb));
		result = ISC_R_FAILURE;
		goto failed;
	}

	state->log(ISC_LOG_INFO, "samba_dlz: started for DN %s",
		   ldb_dn_get_linearized(dn));

	state->auth_context->event_ctx = state->ev_ctx;
	state->auth_context->lp_ctx = state->lp;
	state->auth_context->sam_ctx = state->samdb;
	state->auth_context->generate_session_info_pac = b9_generate_session_info_pac;

	*dbdata = state;

	return ISC_R_SUCCESS;

failed:
	talloc_free(state);
	return result;
}
示例#7
0
int main(int argc, const char *argv[])
{
	TALLOC_CTX				*mem_ctx;
	enum mapistore_error			retval;
	poptContext				pc;
	int					opt;
	struct loadparm_context			*lp_ctx;
	struct ocnotify_private			ocnotify;
	struct mapistore_notification_context	*ctx;
	const char				*opt_server = NULL;
	const char				*opt_newmail = NULL;
	bool					opt_list_server = false;
	bool					ret;
	int					verbosity = 0;
	char					*debuglevel = NULL;
	const char				*sep = NULL;
	uint32_t				i = 0;
	uint32_t				count = 0;
	const char				**hosts = NULL;

	enum { OPT_USERNAME=1000, OPT_BACKEND, OPT_DSTFOLDER, OPT_SEPARATOR, OPT_SERVER, OPT_SERVER_LIST, OPT_FLUSH, OPT_NEWMAIL, OPT_VERBOSE };

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{ "username", 'U', POPT_ARG_STRING, NULL, OPT_USERNAME, "set the username", NULL },
		{ "backend", 'b', POPT_ARG_STRING, NULL, OPT_BACKEND, "set the mapistore backend", NULL },
		{ "dstfolder", 0, POPT_ARG_STRING, NULL, OPT_DSTFOLDER, "set the destination folder", NULL },
		{ "sep", 0, POPT_ARG_STRING, NULL, OPT_SEPARATOR, "set the folder separator", NULL },
		{ "server", 'H', POPT_ARG_STRING, NULL, OPT_SERVER, "set the resolver address", NULL },
		{ "list", 0, POPT_ARG_NONE, NULL, OPT_SERVER_LIST, "list notification service instances", NULL },
		{ "flush", 0, POPT_ARG_NONE, NULL, OPT_FLUSH, "flush notification cache for the user", NULL },
		{ "newmail", 'n', POPT_ARG_STRING, NULL, OPT_NEWMAIL, "send newmail notification and specify .eml", NULL },
		{ "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, "Add one or more -v to increase verbosity", NULL },
		{ NULL, 0, 0, NULL, 0, NULL, NULL }
	};

	mem_ctx = talloc_new(NULL);
	if (!mem_ctx) return 1;

	lp_ctx = loadparm_init_global(true);
	if (!lp_ctx) return 1;

	oc_log_init_stdout();

	memset(&ocnotify, 0, sizeof (struct ocnotify_private));

	pc = poptGetContext("ocnotify", argc, argv, long_options, 0);
	while ((opt = poptGetNextOpt(pc)) != -1) {
		switch (opt) {
		case OPT_USERNAME:
			ocnotify.username = poptGetOptArg(pc);
			break;
		case OPT_BACKEND:
			ocnotify.backend = poptGetOptArg(pc);
			break;
		case OPT_DSTFOLDER:
			ocnotify.dstfolder = poptGetOptArg(pc);
			break;
		case OPT_SEPARATOR:
			sep = poptGetOptArg(pc);
			ocnotify.sep = sep[0];
			break;
		case OPT_SERVER:
			opt_server = poptGetOptArg(pc);
			break;
		case OPT_SERVER_LIST:
			opt_list_server = true;
			break;
		case OPT_FLUSH:
			ocnotify.flush = true;
			break;
		case OPT_NEWMAIL:
			opt_newmail = poptGetOptArg(pc);
			break;
		case OPT_VERBOSE:
			verbosity += 1;
			break;
		}
	}

	if (!ocnotify.username) {
		fprintf(stderr, "[ERR] username not specified\n");
		exit (1);
	}

	debuglevel = talloc_asprintf(mem_ctx, "%u", verbosity);
	ret = lpcfg_set_cmdline(lp_ctx, "log level", debuglevel);
	if (ret == false) {
		oc_log(OC_LOG_FATAL, "unable to set log level");
		exit (1);
	}
	talloc_free(debuglevel);

	if (opt_server) {
		ret = lpcfg_set_cmdline(lp_ctx, "mapistore:notification_cache", opt_server);
		if (ret == false) {
			oc_log(OC_LOG_FATAL, "unable to set mapistore:notification_cache");
			exit (1);
		}
	}

	retval = mapistore_notification_init(mem_ctx, lp_ctx, &ctx);
	if (retval != MAPISTORE_SUCCESS) {
		oc_log(OC_LOG_FATAL, "[ERR] unable to initialize mapistore notification");
		exit(1);
	}
	ocnotify.mstore_ctx.notification_ctx = ctx;

	/* Check if the user is registered */
	retval = mapistore_notification_resolver_exist(&ocnotify.mstore_ctx, ocnotify.username);
	if (retval) {
		oc_log(OC_LOG_ERROR, "[ERR] resolver session: '%s'", mapistore_errstr(retval));
		exit(1);
	}

	/* Retrieve server instances */
	retval = mapistore_notification_resolver_get(mem_ctx, &ocnotify.mstore_ctx, ocnotify.username,
						     &count, &hosts);
	if (retval) {
		oc_log(OC_LOG_ERROR, "[ERR] resolver record: '%s'", mapistore_errstr(retval));
		exit (1);
	}

	if (opt_list_server) {
		oc_log(0, "%d servers found for '%s'\n", count, ocnotify.username);
		for (i = 0; i < count; i++) {
			oc_log(0, "\t* %s\n", hosts[i]);
		}
	}

	/* Send mail notification */
	if (opt_newmail) {
		ocnotify_newmail(mem_ctx, ocnotify, count, hosts, opt_newmail);
	}

	/* Flush invalid data */
	if (ocnotify.flush) {
		for (i = 0; i < count; i++) {
			retval = mapistore_notification_resolver_delete(&ocnotify.mstore_ctx, ocnotify.username, hosts[i]);
		}
	}

	talloc_free(ctx);

	poptFreeContext(pc);
	talloc_free(mem_ctx);
	return 0;
}