From 86d526cd725063932dd700b12111d891c5b420da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ft?= Date: Mon, 4 May 2020 10:40:10 +0200 Subject: [PATCH] fix(core/ldap): When creating a new contact, also write the "sn" field The "sn" attribute is mandatory for "inetOrgPerson" object class, so it should be written otherwise entries cannot be added and fails for example with Entry (cn=73a6-59920600-5-56454280,ou=personal,ou=addressbook,uid=alise,ou=peoples,dc=domain,dc=tld): object class 'inetOrgPerson' requires attribute 'sn' Fixes #4206 Fixes #4248 --- Documentation/SOGoInstallationGuide.asciidoc | 2 ++ Scripts/sogo.conf | 2 ++ SoObjects/SOGo/LDAPSource.h | 2 ++ SoObjects/SOGo/LDAPSource.m | 12 ++++++++++++ 4 files changed, 18 insertions(+) diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index 53fc877c3..19f27fa4f 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -797,6 +797,7 @@ SOGoUserSources = ( { type = ldap; CNFieldName = cn; + SNFieldName = sn; IDFieldName = uid; UIDFieldName = uid; IMAPHostFieldName = mailHost; @@ -840,6 +841,7 @@ SOGoUserSources = ( { type = ldap; CNFieldName = cn; + SNFieldName = sn; IDFieldName = cn; UIDFieldName = sAMAccountName; baseDN = "cn=Users,dc=acme,dc=com"; diff --git a/Scripts/sogo.conf b/Scripts/sogo.conf index b3fa93e38..50901f3d2 100644 --- a/Scripts/sogo.conf +++ b/Scripts/sogo.conf @@ -47,6 +47,7 @@ // { // type = ldap; // CNFieldName = cn; + // SNFieldName = sn; // UIDFieldName = uid; // IDFieldName = uid; // first field of the DN for direct binds // bindFields = (uid, mail); // array of fields to use for indirect binds @@ -66,6 +67,7 @@ // { // type = ldap; // CNFieldName = cn; + // SNFieldName = sn; // UIDFieldName = sAMAccountName; // baseDN = "CN=users,dc=domain,dc=tld"; // bindDN = "CN=sogo,CN=users,DC=domain,DC=tld"; diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index d2446dd96..223220526 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -55,6 +55,7 @@ LDAPSourceSchema *_schema; NSString *_IDField; // the first part of a user DN NSString *_CNField; + NSString *_SNField; NSString *_UIDField; NSArray *_mailFields; NSArray *_searchFields; @@ -102,6 +103,7 @@ - (void) setBaseDN: (NSString *) newBaseDN IDField: (NSString *) newIDField CNField: (NSString *) newCNField + SNField: (NSString *) newSNField UIDField: (NSString *) newUIDField mailFields: (NSArray *) newMailFields searchFields: (NSArray *) newSearchFields diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index c2a8071e5..5eb050bb0 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -91,6 +91,7 @@ static Class NSStringK; _schema = nil; _IDField = @"cn"; /* the first part of a user DN */ _CNField = @"cn"; + _SNField = @"sn"; _UIDField = @"uid"; _mailFields = [[NSArray arrayWithObject: @"mail"] retain]; _contactMapping = nil; @@ -139,6 +140,7 @@ static Class NSStringK; [_pristineBaseDN release]; [_IDField release]; [_CNField release]; + [_SNField release]; [_UIDField release]; [_contactMapping release]; [_mailFields release]; @@ -187,6 +189,7 @@ static Class NSStringK; [self setBaseDN: [udSource objectForKey: @"baseDN"] IDField: [udSource objectForKey: @"IDFieldName"] CNField: [udSource objectForKey: @"CNFieldName"] + SNField: [udSource objectForKey: @"SNFieldName"] UIDField: [udSource objectForKey: @"UIDFieldName"] mailFields: [udSource objectForKey: @"MailFieldNames"] searchFields: [udSource objectForKey: @"SearchFieldNames"] @@ -327,6 +330,7 @@ static Class NSStringK; - (void) setBaseDN: (NSString *) newBaseDN IDField: (NSString *) newIDField CNField: (NSString *) newCNField + SNField: (NSString *) newSNField UIDField: (NSString *) newUIDField mailFields: (NSArray *) newMailFields searchFields: (NSArray *) newSearchFields @@ -345,6 +349,8 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses ASSIGN(_IDField, [newIDField lowercaseString]); if (newCNField) ASSIGN(_CNField, [newCNField lowercaseString]); + if (newSNField) + ASSIGN(_SNField, [newSNField lowercaseString]); if (newUIDField) ASSIGN(_UIDField, [newUIDField lowercaseString]); if (newIMAPHostField) @@ -1216,6 +1222,11 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses if (!value) value = @""; [ldifRecord setObject: value forKey: @"c_cn"]; + + value = [[ldapEntry attributeWithName: _SNField] stringValueAtIndex: 0]; + if (!value) + value = @""; + [ldifRecord setObject: value forKey: @"c_sn"]; /* if "displayName" is not set, we use CNField because it must exist */ if (![ldifRecord objectForKey: @"displayname"]) [ldifRecord setObject: value forKey: @"displayname"]; @@ -1819,6 +1830,7 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection, [ab setBaseDN: [entry dn] IDField: @"cn" CNField: @"displayName" + SNField: @"sn" UIDField: @"cn" mailFields: nil searchFields: nil