From 601c63ae6f4a7de7cb99c5843c7068d053f3a1cd Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 17 Nov 2011 18:30:48 +0000 Subject: [PATCH] Monotone-Parent: 1cc1f0928d45b737424141e1efb38e5b729b89d7 Monotone-Revision: 12ff4c07aa1f796a3312a4e79566255dbd94aece Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-11-17T18:30:48 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 5 +++ OpenChange/MAPIStoreSamDBUtils.h | 34 ++++++++++++++++++ OpenChange/MAPIStoreSamDBUtils.m | 62 ++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 OpenChange/MAPIStoreSamDBUtils.h create mode 100644 OpenChange/MAPIStoreSamDBUtils.m diff --git a/ChangeLog b/ChangeLog index 9410748b3..5de14ea5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2011-11-17 Wolfgang Sourdeau + * OpenChange/MAPIStoreSamDBUtils.m: new module containing helpers + pertaining to the SamDB. + (MAPIStoreSamDBUserAttribute): new function that returns the value + of a specified key from a user record matching one simple criteria. + * OpenChange/MAPIStoreMessage.m (MAPIStoreInternalEntryId): now takes a ldb_context * parameter pointing to the samdb, which enables us: 1) to return the real legacyExchangeDN 2) to make use diff --git a/OpenChange/MAPIStoreSamDBUtils.h b/OpenChange/MAPIStoreSamDBUtils.h new file mode 100644 index 000000000..d8220992f --- /dev/null +++ b/OpenChange/MAPIStoreSamDBUtils.h @@ -0,0 +1,34 @@ +/* MAPIStoreSamDBUtils.h - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef MAPISTORESAMDBUTILS_H +#define MAPISTORESAMDBUTILS_H + +@class NSString; +struct ldb_context; + +NSString *MAPIStoreSamDBUserAttribute (struct ldb_context *samCtx, + NSString *userKey, + NSString *value, + NSString *attributeName); + +#endif /* MAPISTORESAMDBUTILS_H */ diff --git a/OpenChange/MAPIStoreSamDBUtils.m b/OpenChange/MAPIStoreSamDBUtils.m new file mode 100644 index 000000000..ed8d6a0b5 --- /dev/null +++ b/OpenChange/MAPIStoreSamDBUtils.m @@ -0,0 +1,62 @@ +/* MAPIStoreSamDBUtils.m - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#include +#include + +#import "MAPIStoreSamDBUtils.h" + +NSString * +MAPIStoreSamDBUserAttribute (struct ldb_context *samCtx, + NSString *userKey, + NSString *value, + NSString *attributeName) +{ + NSString *resultValue = nil; + const char *attrs[] = { "", NULL }; + NSString *searchFormat; + const char *result; + struct ldb_result *res = NULL; + TALLOC_CTX *memCtx; + int ret; + + memCtx = talloc_zero(NULL, TALLOC_CTX); + + attrs[0] = [attributeName UTF8String]; + searchFormat + = [NSString stringWithFormat: @"(&(objectClass=user)(%@=%%s))", userKey]; + ret = ldb_search (samCtx, memCtx, &res, ldb_get_default_basedn(samCtx), + LDB_SCOPE_SUBTREE, attrs, + [searchFormat UTF8String], + [value UTF8String]); + if (ret == LDB_SUCCESS && res->count == 1) + { + result = ldb_msg_find_attr_as_string (res->msgs[0], attrs[0], NULL); + if (result) + resultValue = [NSString stringWithUTF8String: result]; + } + + talloc_free (memCtx); + + return resultValue; +}