diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 491264e..bfe3b86 100644
--- a/source/param/loadparm.c
+++ b/source/param/loadparm.c
@@ -140,6 +140,8 @@ struct global {
 	char *szPasswordServer;
 	char *szSocketOptions;
 	char *szRealm;
+	char *szEffectiveRealm;
+	bool *bRealmPreserveCase;
 	char *szAfsUsernameMap;
 	int iAfsTokenLifetime;
 	char *szLogNtTokenCommand;
@@ -660,6 +662,8 @@ static bool handle_idmap_uid( int snum, const char *pszParmValue, char **ptr);
 static bool handle_idmap_gid( int snum, const char *pszParmValue, char **ptr);
 static bool handle_debug_list( int snum, const char *pszParmValue, char **ptr );
 static bool handle_workgroup( int snum, const char *pszParmValue, char **ptr );
+static bool handle_realm( int snum, const char *pszParmValue, char **ptr );
+static bool handle_realm_preserve_case( int snum, const char *pszParmValue, char **ptr );
 static bool handle_netbios_aliases( int snum, const char *pszParmValue, char **ptr );
 static bool handle_netbios_scope( int snum, const char *pszParmValue, char **ptr );
 static bool handle_charset( int snum, const char *pszParmValue, char **ptr );
@@ -947,13 +951,22 @@ static struct parm_struct parm_table[] = {
 #ifdef WITH_ADS
 	{
 		.label		= "realm",
-		.type		= P_USTRING,
+		.type		= P_STRING,
 		.p_class	= P_GLOBAL,
-		.ptr		= &Globals.szRealm,
-		.special	= NULL,
+		.ptr		= &Globals.szEffectiveRealm,
+		.special	= handle_realm,
 		.enum_list	= NULL,
 		.flags		= FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
 	},
+	{
+		.label		= "realm preserve case",
+		.type		= P_BOOL,
+		.p_class	= P_GLOBAL,
+		.ptr		= &Globals.bRealmPreserveCase,
+		.special	= handle_realm_preserve_case,
+		.enum_list	= NULL,
+		.flags		= FLAG_BASIC | FLAG_ADVANCED,
+	},
 #endif
 	{
 		.label		= "netbios name",
@@ -5015,7 +5028,7 @@ FN_GLOBAL_STRING(lp_passwd_program, &Globals.szPasswdProgram)
 FN_GLOBAL_STRING(lp_passwd_chat, &Globals.szPasswdChat)
 FN_GLOBAL_STRING(lp_passwordserver, &Globals.szPasswordServer)
 FN_GLOBAL_STRING(lp_name_resolve_order, &Globals.szNameResolveOrder)
-FN_GLOBAL_STRING(lp_realm, &Globals.szRealm)
+FN_GLOBAL_STRING(lp_realm, &Globals.szEffectiveRealm)
 FN_GLOBAL_CONST_STRING(lp_afs_username_map, &Globals.szAfsUsernameMap)
 FN_GLOBAL_INTEGER(lp_afs_token_lifetime, &Globals.iAfsTokenLifetime)
 FN_GLOBAL_STRING(lp_log_nt_token_command, &Globals.szLogNtTokenCommand)
@@ -6855,6 +6868,24 @@ static bool handle_workgroup(int snum, const char *pszParmValue, char **ptr)
 	return ret;
 }
 
+static bool handle_realm(int snum, const char *pszParmValue, char **ptr)
+{
+	string_set(ptr, pszParmValue);
+	string_set(&Globals.szRealm, pszParmValue);
+	if (!Globals.bRealmPreserveCase)
+		strupper_m(*ptr);
+
+	return True;
+}
+
+static bool handle_realm_preserve_case(int snum, const char *pszParmValue, char **ptr)
+{
+	if ((*(bool *)ptr = lp_bool(pszParmValue)))
+		string_set(&Globals.szEffectiveRealm, Globals.szRealm);
+
+	return True;
+}
+
 static bool handle_netbios_scope(int snum, const char *pszParmValue, char **ptr)
 {
 	bool ret;