From c0fefa6cbf8a42aae7d6ad672d474026004b29d7 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 7 Feb 2002 04:42:49 +0000 Subject: [PATCH] * Silently refuse to add directory entries for Internet addresses already belonging to other users. * cdb_trunc() for CtdlDirectoryInit: implemented for GDBM, stubbed for DB --- citadel/ChangeLog | 6 ++++++ citadel/database.c | 16 ++++++++++++++++ citadel/database.h | 2 +- citadel/database_sleepycat.c | 9 +++++++++ citadel/internet_addressing.c | 2 +- citadel/serv_vcard.c | 35 +++++++++++++++++++++++++++++++++-- 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 1b057c29d..984535f5f 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,9 @@ $Log$ + Revision 590.102 2002/02/07 04:42:49 ajc + * Silently refuse to add directory entries for Internet addresses already + belonging to other users. + * cdb_trunc() for CtdlDirectoryInit: implemented for GDBM, stubbed for DB + Revision 590.101 2002/02/05 05:05:53 ajc * Don't crash when posting if the user doesn't have an Internet directory address @@ -3295,3 +3300,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/database.c b/citadel/database.c index f4050722a..6e87a51bc 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -387,6 +387,22 @@ struct cdbdata *cdb_next_item(int cdb) } +/* + * Truncate (delete every record) + */ +void cdb_trunc(int cdb) { + datum key; + + begin_critical_section(S_DATABASE); + key = gdbm_firstkey ( dbf ); + while (key = gdbm_firstkey(gdbms[cdb], key.dptr != NULL) { + gdbm_delete(gdbms[cdb], key); + } + end_critical_section(S_DATABASE); +} + + + /* * empty functions because GDBM doesn't have transaction support */ diff --git a/citadel/database.h b/citadel/database.h index ba74d70a5..2c5ada287 100644 --- a/citadel/database.h +++ b/citadel/database.h @@ -14,4 +14,4 @@ void cdb_end_transaction(void); void cdb_allocate_tsd(void); void cdb_free_tsd(void); void cdb_check_handles(void); - +void cdb_trunc(int cdb); diff --git a/citadel/database_sleepycat.c b/citadel/database_sleepycat.c index 45cff4dc2..62c3deb9f 100644 --- a/citadel/database_sleepycat.c +++ b/citadel/database_sleepycat.c @@ -664,6 +664,15 @@ struct cdbdata *cdb_next_item(int cdb) } + +/* + * Truncate (delete every record) + */ +void cdb_trunc(int cdb) { + /* FIXME this needs to be implemented */ +} + + /* * Transaction-based stuff. I'm writing this as I bake cookies... */ diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index d0d575a0c..741c563fe 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -576,7 +576,7 @@ int IsDirectory(char *addr) { * Initialize the directory database (erasing anything already there) */ void CtdlDirectoryInit(void) { - /* FIXME ... write this */ + cdb_trunc(CDB_DIRECTORY); } diff --git a/citadel/serv_vcard.c b/citadel/serv_vcard.c index 275b4a8d0..f9853303e 100644 --- a/citadel/serv_vcard.c +++ b/citadel/serv_vcard.c @@ -4,7 +4,7 @@ * A server-side module for Citadel which supports address book information * using the standard vCard format. * - * Copyright (c) 1999-2001 / released under the GNU General Public License + * Copyright (c) 1999-2002 / released under the GNU General Public License */ /* @@ -118,6 +118,37 @@ void vcard_extract_internet_addresses(struct CtdlMessage *msg, vcard_free(v); } + + +/* + * Callback for vcard_add_to_directory() + * (Lotsa ugly nested callbacks. Oh well.) + * This little shim function makes sure we're not + */ +void vcard_directory_add_user(char *internet_addr, char *citadel_addr) { + char buf[SIZ]; + + /* We have to validate that we're not stepping on someone else's + * email address ... but only if we're logged in. Otherwise it's + * probably just the networker or something. + */ + if (CC->logged_in) { + lprintf(9, "Checking for <%s>...\n", internet_addr); + if (CtdlDirectoryLookup(buf, internet_addr) == 0) { + if (strcasecmp(buf, citadel_addr)) { + /* This address belongs to someone else. + * Bail out silently without saving. + */ + lprintf(9, "DOOP!\n"); + return; + } + } + } + lprintf(9, "ADDING!\n"); + CtdlDirectoryAddUser(internet_addr, citadel_addr); +} + + /* * Back end function for cmd_igab() */ @@ -126,7 +157,7 @@ void vcard_add_to_directory(long msgnum, void *data) { msg = CtdlFetchMessage(msgnum); if (msg != NULL) { - vcard_extract_internet_addresses(msg, CtdlDirectoryAddUser); + vcard_extract_internet_addresses(msg, vcard_directory_add_user); } CtdlFreeMessage(msg); -- 2.30.2