Skip to content

Commit

Permalink
fix(core/ldap): When creating a new contact, also write the "sn" field
Browse files Browse the repository at this point in the history
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
  • Loading branch information
the-nic committed Aug 18, 2020
1 parent 6aca61d commit 86d526c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Documentation/SOGoInstallationGuide.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ SOGoUserSources = (
{
type = ldap;
CNFieldName = cn;
SNFieldName = sn;
IDFieldName = uid;
UIDFieldName = uid;
IMAPHostFieldName = mailHost;
Expand Down Expand Up @@ -840,6 +841,7 @@ SOGoUserSources = (
{
type = ldap;
CNFieldName = cn;
SNFieldName = sn;
IDFieldName = cn;
UIDFieldName = sAMAccountName;
baseDN = "cn=Users,dc=acme,dc=com";
Expand Down
2 changes: 2 additions & 0 deletions Scripts/sogo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions SoObjects/SOGo/LDAPSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions SoObjects/SOGo/LDAPSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ - (id) init
_schema = nil;
_IDField = @"cn"; /* the first part of a user DN */
_CNField = @"cn";
_SNField = @"sn";
_UIDField = @"uid";
_mailFields = [[NSArray arrayWithObject: @"mail"] retain];
_contactMapping = nil;
Expand Down Expand Up @@ -139,6 +140,7 @@ - (void) dealloc
[_pristineBaseDN release];
[_IDField release];
[_CNField release];
[_SNField release];
[_UIDField release];
[_contactMapping release];
[_mailFields release];
Expand Down Expand Up @@ -187,6 +189,7 @@ - (id) initFromUDSource: (NSDictionary *) udSource
[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"]
Expand Down Expand Up @@ -327,6 +330,7 @@ - (void) setBindDN: (NSString *) newBindDN
- (void) setBaseDN: (NSString *) newBaseDN
IDField: (NSString *) newIDField
CNField: (NSString *) newCNField
SNField: (NSString *) newSNField
UIDField: (NSString *) newUIDField
mailFields: (NSArray *) newMailFields
searchFields: (NSArray *) newSearchFields
Expand All @@ -345,6 +349,8 @@ - (void) setBaseDN: (NSString *) newBaseDN
ASSIGN(_IDField, [newIDField lowercaseString]);
if (newCNField)
ASSIGN(_CNField, [newCNField lowercaseString]);
if (newSNField)
ASSIGN(_SNField, [newSNField lowercaseString]);
if (newUIDField)
ASSIGN(_UIDField, [newUIDField lowercaseString]);
if (newIMAPHostField)
Expand Down Expand Up @@ -1216,6 +1222,11 @@ - (NSDictionary *) _convertLDAPEntryToContact: (NGLdapEntry *) ldapEntry
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"];
Expand Down Expand Up @@ -1819,6 +1830,7 @@ - (NSArray *) addressBookSourcesForUser: (NSString *) theUser
[ab setBaseDN: [entry dn]
IDField: @"cn"
CNField: @"displayName"
SNField: @"sn"
UIDField: @"cn"
mailFields: nil
searchFields: nil
Expand Down

0 comments on commit 86d526c

Please sign in to comment.