From 74293426d9b88dad1fffa1762d2be83b1eb45d02 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 24 May 2012 13:52:07 -0400 Subject: Normalize uid to lower case in winsync. This in effect fixes uid, krbPrincipalName and homeDir. https://fedorahosted.org/freeipa/ticket/2756 --- .../ipa-slapi-plugins/ipa-winsync/ipa-winsync.c | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.c b/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.c index ef237e93a..5d9e3cf94 100644 --- a/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.c +++ b/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.c @@ -61,6 +61,7 @@ #include #include +#include #include "plstr.h" static void @@ -82,6 +83,25 @@ do_force_sync( int *do_modify /* set to true if mods were applied */ ); +static char * +str_tolower(char *str) +{ + char *lstr, *t; + + lstr = strdup(str); + if (!lstr) { + /* the caller should log OOM if this returns NULL */ + return NULL; + } + + for (t = lstr; *t; t++) + if (isalpha(*t)) + *t = tolower(*t); + + return lstr; +} + + /* This is called when a new agreement is created or loaded at startup. */ @@ -278,11 +298,22 @@ ipa_winsync_pre_ds_add_user_cb(void *cbdata, const Slapi_Entry *rawentry, if (slapi_entry_attr_find(ds_entry, type, &e_attr) || !e_attr) { char *upn = NULL; char *uid = NULL; + char *lower = NULL; char *samAccountName = NULL; /* if the ds_entry already has a uid, use that */ if ((uid = slapi_entry_attr_get_charptr(ds_entry, "uid"))) { - upn = slapi_ch_smprintf("%s@%s", uid, ipaconfig->realm_name); + lower = str_tolower(uid); + if (!lower) { + LOG_OOM(); + return; + } + /* Now reset UID to be lower-case */ slapi_ch_free_string(&uid); + slapi_entry_attr_delete(ds_entry, "uid"); + slapi_entry_attr_set_charptr(ds_entry, "uid", lower); + /* And create a normalized principal */ + upn = slapi_ch_smprintf("%s@%s", lower, ipaconfig->realm_name); + free(lower); /* otherwise, use the samAccountName from the ad_entry */ } else if ((samAccountName = slapi_entry_attr_get_charptr(ad_entry, "samAccountName"))) { -- cgit