getuserbyuid() now uses the extauth index, so we can do ldap sync
[citadel.git] / citadel / modules / upgrade / serv_upgrade.c
index 7cf4d869aa718f2d3c6e22f6b05615188865a10f..56ba219df0044f594d7395e0fc3005b3a2fa511b 100644 (file)
@@ -100,13 +100,13 @@ void fix_sys_user_name(void)
 
 
 /* 
- * Back end processing function for convert_ctdluid_to_minusone()
+ * Back end processing function for reindex_uids()
  * Call this function as a ForEachUser backend in order to queue up
- * room names, or call it with a null user to make it do the processing.
+ * user names, or call it with a null user to make it do the processing.
  * This allows us to maintain the list as a static instead of passing
  * pointers around.
  */
-void cbtm_backend(struct ctdluser *usbuf, void *data) {
+void reindex_uids_backend(struct ctdluser *usbuf, void *data) {
        static struct UserProcList *uplist = NULL;
        struct UserProcList *ptr;
        struct ctdluser us;
@@ -114,9 +114,10 @@ void cbtm_backend(struct ctdluser *usbuf, void *data) {
        /* this is the calling mode where we add a user */
 
        if (usbuf != NULL) {
-               ptr = (struct UserProcList *)
-                       malloc(sizeof (struct UserProcList));
-               if (ptr == NULL) return;
+               ptr = (struct UserProcList *) malloc(sizeof (struct UserProcList));
+               if (ptr == NULL) {
+                       return;
+               }
 
                safestrncpy(ptr->user, usbuf->fullname, sizeof ptr->user);
                ptr->next = uplist;
@@ -129,11 +130,21 @@ void cbtm_backend(struct ctdluser *usbuf, void *data) {
        while (uplist != NULL) {
 
                if (CtdlGetUserLock(&us, uplist->user) == 0) {
-                       syslog(LOG_DEBUG, "Processing <%s>...", uplist->user);
+                       syslog(LOG_DEBUG, "Processing <%s> (%d)", uplist->user, us.uid);
                        if (us.uid == CTDLUID) {
-                               us.uid = (-1);
+                               us.uid = NATIVE_AUTH_UID;
                        }
                        CtdlPutUserLock(&us);
+                       if ((us.uid > 0) && (us.uid != NATIVE_AUTH_UID)) {              // if non-native auth , index by uid
+
+                               syslog(LOG_DEBUG, "\033[31m attaching %d to %s \033[0m", us.uid , us.fullname);
+
+
+                               StrBuf *claimed_id = NewStrBuf();
+                               StrBufPrintf(claimed_id, "uid:%d", us.uid);
+                               attach_extauth(&us, claimed_id);
+                               FreeStrBuf(&claimed_id);
+                       }
                }
 
                ptr = uplist;
@@ -143,12 +154,13 @@ void cbtm_backend(struct ctdluser *usbuf, void *data) {
 }
 
 /*
- * quick fix to change all CTDLUID users to (-1)
+ * Build extauth index of all users with uid-based join (system auth, LDAP auth)
+ * Also changes all users with a uid of CTDLUID to NATIVE_AUTH_UID (-1)
  */
-void convert_ctdluid_to_minusone(void) {
-       syslog(LOG_WARNING, "Applying uid changes");
-       ForEachUser(cbtm_backend, NULL);
-       cbtm_backend(NULL, NULL);
+void reindex_uids(void) {
+       syslog(LOG_WARNING, "upgrade: reindexing and applying uid changes");
+       ForEachUser(reindex_uids_backend, NULL);
+       reindex_uids_backend(NULL, NULL);
        return;
 }
 
@@ -429,7 +441,7 @@ void update_config(void) {
  * Helper function for move_inet_addrs_from_vcards_to_user_records()
  *
  * Call this function as a ForEachUser backend in order to queue up
- * room names, or call it with a null user to make it do the processing.
+ * user names, or call it with a null user to make it do the processing.
  * This allows us to maintain the list as a static instead of passing
  * pointers around.
  */
@@ -484,8 +496,6 @@ void miafvtur_backend(struct ctdluser *usbuf, void *data) {
        int i;
        struct ctdluser u;
 
-       CtdlRebuildDirectoryIndex();
-
        for (i=0; i<num_m; ++i) {
                syslog(LOG_DEBUG, "<%s> = <%s>", m[i].name, m[i].emails);
                if (CtdlGetUser(&u, m[i].name) == 0) {
@@ -496,7 +506,6 @@ void miafvtur_backend(struct ctdluser *usbuf, void *data) {
        free(m);
        num_m = 0;
        alloc_m = 0;
-       abort();
        return;
 }
 
@@ -509,6 +518,7 @@ void move_inet_addrs_from_vcards_to_user_records(void)
 {
        ForEachUser(miafvtur_backend, NULL);
        miafvtur_backend(NULL, NULL);
+       CtdlRebuildDirectoryIndex();
 }
 
 
@@ -533,8 +543,8 @@ void check_server_upgrades(void) {
                syslog(LOG_EMERG, "This database is too old to be upgraded.  Citadel server will exit.");
                exit(EXIT_FAILURE);
        }
-       if ((CtdlGetConfigInt("MM_hosted_upgrade_level") > 000) && (CtdlGetConfigInt("MM_hosted_upgrade_level") < 608)) {
-               convert_ctdluid_to_minusone();
+       if ((CtdlGetConfigInt("MM_hosted_upgrade_level") > 000) && (CtdlGetConfigInt("MM_hosted_upgrade_level") < 913)) {
+               reindex_uids();
        }
        if ((CtdlGetConfigInt("MM_hosted_upgrade_level") > 000) && (CtdlGetConfigInt("MM_hosted_upgrade_level") < 659)) {
                rebuild_euid_index();
@@ -554,10 +564,6 @@ void check_server_upgrades(void) {
                        QRoom.QRdefaultview = VIEW_QUEUE;
                        CtdlPutRoom(&QRoom);
                }
-               if (!CtdlGetRoom(&QRoom, FNBL_QUEUE_ROOM)) {
-                       QRoom.QRdefaultview = VIEW_QUEUE;
-                       CtdlPutRoom(&QRoom);
-               }
        }
 
        if ((CtdlGetConfigInt("MM_hosted_upgrade_level") > 000) && (CtdlGetConfigInt("MM_hosted_upgrade_level") < 902)) {