[dovecot-cvs] dovecot/src/master main.c, 1.77, 1.78 master-settings.c, 1.118, 1.119 master-settings.h, 1.77, 1.78

cras at dovecot.org cras at dovecot.org
Sun Apr 9 14:07:38 EEST 2006


Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv676

Modified Files:
	main.c master-settings.c master-settings.h 
Log Message:
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
bit ugly code, but it'll do until the whole config handling gets rewritten
in Dovecot 2.0.



Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/main.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- main.c	5 Feb 2006 18:00:15 -0000	1.77
+++ main.c	9 Apr 2006 11:07:36 -0000	1.78
@@ -706,6 +706,7 @@
 	/* parse arguments */
 	const char *exec_protocol = NULL, *exec_section = NULL, *user, *home;
 	bool foreground = FALSE, ask_key_pass = FALSE;
+	bool dump_config = FALSE, dump_config_nondefaults = FALSE;
 	int i;
 
 #ifdef DEBUG
@@ -719,11 +720,15 @@
 		if (strcmp(argv[i], "-F") == 0) {
 			/* foreground */
 			foreground = TRUE;
+		} else if (strcmp(argv[i], "-a") == 0) {
+			dump_config = TRUE;
 		} else if (strcmp(argv[i], "-c") == 0) {
 			/* config file */
 			i++;
 			if (i == argc) i_fatal("Missing config file argument");
 			configfile = argv[i];
+		} else if (strcmp(argv[i], "-n") == 0) {
+			dump_config_nondefaults = TRUE;
 		} else if (strcmp(argv[i], "-p") == 0) {
 			/* Ask SSL private key password */
 			ask_key_pass = TRUE;
@@ -763,6 +768,11 @@
 		exit(FATAL_DEFAULT);
 	t_pop();
 
+	if (dump_config || dump_config_nondefaults) {
+		master_settings_dump(settings_root, dump_config_nondefaults);
+		return 0;
+	}
+
 	if (ask_key_pass) {
 		const char *prompt;
 

Index: master-settings.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/master-settings.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- master-settings.c	2 Apr 2006 09:18:49 -0000	1.118
+++ master-settings.c	9 Apr 2006 11:07:36 -0000	1.119
@@ -1234,6 +1234,171 @@
 	return TRUE;
 }
 
+static void settings_dump(const struct setting_def *def, const void **sets,
+			  const char **set_names, unsigned int count,
+			  bool nondefaults, unsigned int indent)
+{
+	const char **str;
+	unsigned int i;
+
+	str = t_new(const char *, count);
+	for (; def->name != NULL; def++) {
+		bool same = TRUE;
+
+		t_push();
+		switch (def->type) {
+		case SET_STR: {
+			const char *const *strp;
+
+			for (i = 0; i < count; i++) {
+				strp = CONST_PTR_OFFSET(sets[i], def->offset);
+				str[i] = *strp != NULL ? *strp : "";
+			}
+			break;
+		}
+		case SET_INT: {
+			const unsigned int *n;
+
+			for (i = 0; i < count; i++) {
+				n = CONST_PTR_OFFSET(sets[i], def->offset);
+				str[i] = dec2str(*n);
+			}
+			break;
+		}
+		case SET_BOOL: {
+			const bool *b;
+
+			for (i = 0; i < count; i++) {
+				b = CONST_PTR_OFFSET(sets[i], def->offset);
+				str[i] = *b ? "yes" : "no";
+			}
+			break;
+		}
+		}
+
+		for (i = 2; i < count; i++) {
+			if (strcmp(str[i], str[i-1]) != 0)
+				same = FALSE;
+		}
+		if (same) {
+			if (!nondefaults || strcmp(str[0], str[1]) != 0) {
+				for (i = 0; i < indent; i++)
+					putc(' ', stdout);
+				printf("%s: %s\n", def->name, str[1]);
+			}
+		} else {
+			for (i = 0; i < indent; i++)
+				putc(' ', stdout);
+			for (i = 1; i < count; i++) {
+				printf("%s(%s): %s\n", def->name,
+				       set_names[i], str[i]);
+			}
+		}
+	}
+}
+
+static void
+namespace_settings_dump(struct namespace_settings *ns, bool nondefaults)
+{
+	const void *sets[2];
+
+	sets[0] = t_malloc0(sizeof(struct namespace_settings));
+	for (; ns != NULL; ns = ns->next) {
+		printf("namespace:\n");
+		sets[1] = ns;
+		settings_dump(namespace_setting_defs, sets, NULL, 2,
+			      nondefaults, 2);
+	}
+}
+
+static void auth_settings_dump(struct auth_settings *auth, bool nondefaults)
+{
+	const struct auth_passdb_settings *passdb;
+	const struct auth_userdb_settings *userdb;
+	const struct auth_socket_settings *socket;
+	const void *sets[2], *sets2[2];
+	const void *empty_defaults;
+
+	empty_defaults = t_malloc0(sizeof(struct auth_passdb_settings) +
+				   sizeof(struct auth_userdb_settings) +
+				   sizeof(struct auth_socket_settings));
+
+	sets[0] = &default_auth_settings;
+	sets2[0] = empty_defaults;
+
+	for (; auth != NULL; auth = auth->next) {
+		printf("auth %s:\n", auth->name);
+		sets[1] = auth;
+		settings_dump(auth_setting_defs, sets, NULL, 2, nondefaults, 2);
+
+		passdb = auth->passdbs;
+		for (; passdb != NULL; passdb = passdb->next) {
+			printf("  passdb:\n");
+			sets2[1] = passdb;
+			settings_dump(auth_passdb_setting_defs, sets2, NULL, 2,
+				      nondefaults, 4);
+		}
+
+		userdb = auth->userdbs;
+		for (; userdb != NULL; userdb = userdb->next) {
+			printf("  userdb:\n");
+			sets2[1] = userdb;
+			settings_dump(auth_userdb_setting_defs, sets2, NULL, 2,
+				      nondefaults, 4);
+		}
+
+		socket = auth->sockets;
+		for (; socket != NULL; socket = socket->next) {
+			printf("  socket:\n");
+			sets2[1] = socket;
+			settings_dump(auth_socket_setting_defs, sets2, NULL, 2,
+				      nondefaults, 4);
+
+			if (socket->client.path != NULL) {
+				printf("    client:\n");
+				sets2[1] = &socket->client;
+				settings_dump(socket_setting_defs, sets2, NULL,
+					      2, nondefaults, 6);
+			}
+
+			if (socket->master.path != NULL) {
+				printf("    master:\n");
+				sets2[1] = &socket->master;
+				settings_dump(socket_setting_defs, sets2, NULL,
+					      2, nondefaults, 6);
+			}
+		}
+	}
+}
+
+void master_settings_dump(struct server_settings *set, bool nondefaults)
+{
+	const void *sets[4];
+	const char *set_names[4];
+	unsigned int count;
+
+	sets[0] = &default_settings;
+	sets[1] = set->defaults;
+
+	set_names[0] = NULL;
+	set_names[1] = "default";
+
+	count = 2;
+	if (set->imap != NULL) {
+		sets[count] = set->imap;
+		set_names[count] = "imap";
+		count++;
+	}
+	if (set->pop3 != NULL) {
+		sets[count] = set->pop3;
+		set_names[count] = "pop3";
+		count++;
+	}
+	settings_dump(setting_defs, sets, set_names, count, nondefaults, 0);
+	namespace_settings_dump(set->namespaces, nondefaults);
+	auth_settings_dump(set->auths, nondefaults);
+}
+
 void master_settings_init(void)
 {
 	settings_pool = pool_alloconly_create("settings", 4096);

Index: master-settings.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/master-settings.h,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- master-settings.h	27 Mar 2006 12:54:27 -0000	1.77
+++ master-settings.h	9 Apr 2006 11:07:36 -0000	1.78
@@ -223,6 +223,8 @@
 
 bool master_settings_read(const char *path, bool nochecks);
 
+void master_settings_dump(struct server_settings *set, bool nondefaults);
+
 void master_settings_init(void);
 void master_settings_deinit(void);
 



More information about the dovecot-cvs mailing list