* Silently refuse to add directory entries for Internet addresses already
authorArt Cancro <ajc@citadel.org>
Thu, 7 Feb 2002 04:42:49 +0000 (04:42 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 7 Feb 2002 04:42:49 +0000 (04:42 +0000)
  belonging to other users.
* cdb_trunc() for CtdlDirectoryInit: implemented for GDBM, stubbed for DB

citadel/ChangeLog
citadel/database.c
citadel/database.h
citadel/database_sleepycat.c
citadel/internet_addressing.c
citadel/serv_vcard.c

index 1b057c29d0aa9abe1e9655b90b6a56121e85a0dc..984535f5f2789d9ab2743b42db435d5829e498d8 100644 (file)
@@ -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 <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index f4050722aee171b2dff9cdf8a59e369159bffc72..6e87a51bcb895a2fe3ef150c89af6caa62569376 100644 (file)
@@ -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
  */
index ba74d70a5bc13fc7622b22cbe2f9a403fed2e27c..2c5ada2874011275b2997b84de79fbc6587b6398 100644 (file)
@@ -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);
index 45cff4dc2e30c46c9a679b5a1ebac9e6ad67b50e..62c3deb9f4f6994a1e8216adb2aabac3fe04da47 100644 (file)
@@ -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...
  */
index d0d575a0c63feda5a4aa91bd723632cd32039eaf..741c563fe5ae9196ecd069e2e58580b69fc74a3f 100644 (file)
@@ -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);
 }
 
 
index 275b4a8d04d95cc6a45634757df139f47b837916..f9853303e5dd461041c6dfd0e3bd0cf89a570401 100644 (file)
@@ -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);