]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_vcard.c
* THIS IS 7.05
[citadel.git] / citadel / serv_vcard.c
index a106a872f3a4ba7669ecc1cd8a70bc419faf5d72..dda653694ee8f423127d4f2538ba879c96c612ce 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-2002 / released under the GNU General Public License
+ * Copyright (c) 1999-2007 / released under the GNU General Public License
  */
 
 /*
@@ -58,6 +58,7 @@
 #include "tools.h"
 #include "vcard.h"
 #include "serv_ldap.h"
+#include "serv_vcard.h"
 
 /*
  * set global flag calling for an aide to validate new users
@@ -188,7 +189,7 @@ void cmd_igab(char *argbuf) {
        CtdlDirectoryInit();
 
        /* We want *all* vCards in this room */
-       CtdlForEachMessage(MSGS_ALL, 0, "text/x-vcard",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/x-vcard",
                NULL, vcard_add_to_directory, NULL);
 
        getroom(&CC->room, hold_rm);    /* return to saved room */
@@ -200,9 +201,9 @@ void cmd_igab(char *argbuf) {
 
 /*
  * See if there is a valid Internet address in a vCard to use for outbound
- * Internet messages.  If there is, stick it in CC->cs_inet_email.
+ * Internet messages.  If there is, stick it in the buffer.
  */
-void vcard_populate_cs_inet_email(struct vCard *v) {
+void extract_primary_inet_email(char *emailaddrbuf, size_t emailaddrbuf_len, struct vCard *v) {
        char *s, *addr;
        int continue_searching = 1;
        int instance = 0;
@@ -219,10 +220,8 @@ void vcard_populate_cs_inet_email(struct vCard *v) {
                        if (strlen(addr) > 0) {
                                if (IsDirectory(addr)) {
                                        continue_searching = 0;
-                                       safestrncpy(CC->cs_inet_email,
-                                               addr,
-                                               sizeof(CC->cs_inet_email)
-                                       );
+                                       safestrncpy(emailaddrbuf, addr,
+                                               emailaddrbuf_len);
                                }
                        }
                        free(addr);
@@ -235,6 +234,26 @@ void vcard_populate_cs_inet_email(struct vCard *v) {
 
 
 
+/*
+ * See if there is a name / screen name / friendly name  in a vCard to use for outbound
+ * Internet messages.  If there is, stick it in the buffer.
+ */
+void extract_friendly_name(char *namebuf, size_t namebuf_len, struct vCard *v)
+{
+       char *s;
+
+       s = vcard_get_prop(v, "fn", 0, 0, 0);
+       if (s == NULL) {
+               s = vcard_get_prop(v, "n", 0, 0, 0);
+       }
+
+       if (s != NULL) {
+               safestrncpy(namebuf, s, namebuf_len);
+       }
+}
+
+
+
 /*
  * This handler detects whether the user is attempting to save a new
  * vCard as part of his/her personal configuration, and handles the replace
@@ -261,10 +280,18 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
           && (!strcasecmp(&CC->room.QRname[11], USERCONFIGROOM)) ) {
                /* Yes, we want to do this */
                yes_my_citadel_config = 1;
+
+#ifdef VCARD_SAVES_BY_AIDES_ONLY
+               /* Prevent non-aides from performing registration changes */
+               if (CC->user.axlevel < 6) {
+                       return(1);
+               }
+#endif
+
        }
 
        /* Is this a room with an address book in it? */
-       if (CC->curr_view == VIEW_ADDRESSBOOK) {
+       if (CC->room.QRdefaultview == VIEW_ADDRESSBOOK) {
                yes_any_vcard_room = 1;
        }
 
@@ -315,8 +342,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                                 * want to make sure there is absolutely only one
                                 * vCard in the user's config room at all times.
                                 */
-                               CtdlDeleteMessages(CC->room.QRname,
-                                               0L, "text/x-vcard", 1);
+                               CtdlDeleteMessages(CC->room.QRname, NULL, 0, "text/x-vcard");
 
                                /* Make the author of the message the name of the user.
                                 */
@@ -451,7 +477,8 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
 
                        /* Store our Internet return address in memory */
                        v = vcard_load(msg->cm_fields['M']);
-                       vcard_populate_cs_inet_email(v);
+                       extract_primary_inet_email(CC->cs_inet_email, sizeof CC->cs_inet_email, v);
+                       extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v);
                        vcard_free(v);
 
                        /* Put it in the Global Address Book room... */
@@ -500,7 +527,7 @@ void vcard_gu_backend(long supplied_msgnum, void *userdata) {
 struct vCard *vcard_get_user(struct ctdluser *u) {
        char hold_rm[ROOMNAMELEN];
        char config_rm[ROOMNAMELEN];
-       struct CtdlMessage *msg;
+       struct CtdlMessage *msg = NULL;
        struct vCard *v;
        long VCmsgnum;
 
@@ -514,7 +541,7 @@ struct vCard *vcard_get_user(struct ctdluser *u) {
 
        /* We want the last (and probably only) vcard in this room */
        VCmsgnum = (-1);
-       CtdlForEachMessage(MSGS_LAST, 1, "text/x-vcard",
+       CtdlForEachMessage(MSGS_LAST, 1, NULL, "text/x-vcard",
                NULL, vcard_gu_backend, (void *)&VCmsgnum );
        getroom(&CC->room, hold_rm);    /* return to saved room */
 
@@ -540,7 +567,7 @@ void vcard_write_user(struct ctdluser *u, struct vCard *v) {
        FILE *fp;
        char *ser;
 
-       strcpy(temp, tmpnam(NULL));
+       CtdlMakeTempFileName(temp, sizeof temp);
        ser = vcard_serialize(v);
 
        fp = fopen(temp, "w");
@@ -848,6 +875,22 @@ EOH:       CtdlFreeMessage(msg);
 
 
 
+/*
+ * Get Valid Screen Names
+ */
+void cmd_gvsn(char *argbuf)
+{
+       if (CtdlAccessCheck(ac_logged_in)) return;
+
+       cprintf("%d valid screen names:\n", LISTING_FOLLOWS);
+       cprintf("%s\n", CC->user.fullname);
+       if ( (strlen(CC->cs_inet_fn) > 0) && (strcasecmp(CC->user.fullname, CC->cs_inet_fn)) ) {
+               cprintf("%s\n", CC->cs_inet_fn);
+       }
+       cprintf("000\n");
+}
+
+
 /*
  * Query Directory
  */
@@ -868,6 +911,56 @@ void cmd_qdir(char *argbuf) {
        cprintf("%d %s\n", CIT_OK, citadel_addr);
 }
 
+/*
+ * Query Directory, in fact an alias to match postfix tcp auth.
+ */
+void check_get(void) {
+       char internet_addr[256];
+
+       char cmdbuf[SIZ];
+
+       time(&CC->lastcmd);
+       memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
+       if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
+               lprintf(CTDL_CRIT, "Client disconnected: ending session.\n");
+               CC->kill_me = 1;
+               return;
+       }
+       lprintf(CTDL_INFO, ": %s\n", cmdbuf);
+       while (strlen(cmdbuf) < 3) strcat(cmdbuf, " ");
+
+       if (strcasecmp(cmdbuf, "GET "));
+       {
+               struct recptypes *rcpt;
+               char *argbuf = &cmdbuf[4];
+               
+               extract_token(internet_addr, argbuf, 0, '|', sizeof internet_addr);
+               rcpt = validate_recipients(internet_addr);
+               if ((rcpt != NULL)&&
+                       (
+                        (*rcpt->recp_local != '\0')||
+                        (*rcpt->recp_room != '\0')||
+                        (*rcpt->recp_ignet != '\0')))
+               {
+
+                       cprintf("200 OK %s\n", internet_addr);
+                       lprintf(CTDL_INFO, "sending 200 OK for the room %s\n", rcpt->display_recp);
+               }
+               else 
+               {
+                       cprintf("500 REJECT noone here by that name.\n");
+                       
+                       lprintf(CTDL_INFO, "sending 500 REJECT noone here by that name: %s\n", internet_addr);
+               }
+               if (rcpt != NULL) free (rcpt);
+       }
+///    CC->kill_me = 1;
+}
+
+void check_get_greeting(void) {
+/* dummy function, we have no greeting in this verry simple protocol. */
+}
+
 
 /*
  * We don't know if the Contacts room exists so we just create it at login
@@ -904,11 +997,11 @@ void vcard_create_room(void)
  * When a user logs in...
  */
 void vcard_session_login_hook(void) {
-       struct vCard *v;
+       struct vCard *v = NULL;
 
        v = vcard_get_user(&CC->user);
-       vcard_populate_cs_inet_email(v);
-
+       extract_primary_inet_email(CC->cs_inet_email, sizeof CC->cs_inet_email, v);
+       extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v);
        vcard_free(v);
 
        vcard_create_room();
@@ -954,7 +1047,7 @@ struct vCard *vcard_new_from_rfc822_addr(char *addr) {
  */
 void strip_addresses_already_have(long msgnum, void *userdata) {
        char *collected_addresses;
-       struct CtdlMessage *msg;
+       struct CtdlMessage *msg = NULL;
        struct vCard *v;
        char *value = NULL;
        int i, j;
@@ -1001,7 +1094,7 @@ void store_this_ha(struct addresses_to_be_filed *aptr) {
 
        /* First remove any addresses we already have in the address book */
        usergoto(aptr->roomname, 0, 0, NULL, NULL);
-       CtdlForEachMessage(MSGS_ALL, 0, "text/x-vcard", NULL,
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/x-vcard", NULL,
                strip_addresses_already_have, aptr->collected_addresses);
 
        if (strlen(aptr->collected_addresses) > 0)
@@ -1065,7 +1158,7 @@ void store_harvested_addresses(void) {
 
 
 /* 
- * Function to output a vCard as plain text.  Nobody uses MSG0 anymore, so
+ * Function to output vCard data as plain text.  Nobody uses MSG0 anymore, so
  * really this is just so we expose the vCard data to the full text indexer.
  */
 void vcard_fixed_output(char *ptr, int len) {
@@ -1074,7 +1167,6 @@ void vcard_fixed_output(char *ptr, int len) {
        char *key, *value;
        int i = 0;
 
-       cprintf("vCard:\n");
        serialized_vcard = malloc(len + 1);
        safestrncpy(serialized_vcard, ptr, len+1);
        v = vcard_load(serialized_vcard);
@@ -1083,17 +1175,30 @@ void vcard_fixed_output(char *ptr, int len) {
        i = 0;
        while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
                value = vcard_get_prop(v, "", 0, i++, 0);
-               cprintf("%20s : %s\n", key, value);
+               cprintf("%s\n", value);
        }
 
        vcard_free(v);
 }
 
 
+char *serv_postfix_tcpdict(void)
+{
+       CtdlRegisterServiceHook(config.c_pftcpdict_port,        /* Postfix */
+                               NULL,
+                               check_get_greeting,
+                               check_get,
+                               NULL);
+       return "$Id$";
+}
+
+
 
 char *serv_vcard_init(void)
 {
        struct ctdlroom qr;
+       char filename[256];
+       FILE *fp;
 
        CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN);
        CtdlRegisterMessageHook(vcard_upload_beforesave, EVT_BEFORESAVE);
@@ -1104,6 +1209,7 @@ char *serv_vcard_init(void)
        CtdlRegisterProtoHook(cmd_igab, "IGAB",
                                        "Initialize Global Address Book");
        CtdlRegisterProtoHook(cmd_qdir, "QDIR", "Query Directory");
+       CtdlRegisterProtoHook(cmd_gvsn, "GVSN", "Get Valid Screen Names");
        CtdlRegisterUserHook(vcard_newuser, EVT_NEWUSER);
        CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
        CtdlRegisterNetprocHook(vcard_extract_from_network);
@@ -1118,6 +1224,17 @@ char *serv_vcard_init(void)
                qr.QRep.expire_mode = EXPIRE_MANUAL;
                qr.QRdefaultview = VIEW_ADDRESSBOOK;    /* 2 = address book view */
                lputroom(&qr);
+
+               /*
+                * Also make sure it has a netconfig file, so the networker runs
+                * on this room even if we don't share it with any other nodes.
+                * This allows the CANCEL messages (i.e. "Purge this vCard") to be
+                * purged.
+                */
+               assoc_file_name(filename, sizeof filename, &qr, ctdl_netcfg_dir);
+               fp = fopen(filename, "a");
+               if (fp != NULL) fclose(fp);
+               chown(filename, CTDLUID, (-1));
        }
 
        return "$Id$";