* When saving a netconfigs file, citserver now copies
authorArt Cancro <ajc@citadel.org>
Mon, 24 Sep 2007 14:28:57 +0000 (14:28 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 24 Sep 2007 14:28:57 +0000 (14:28 +0000)
  the tempfile to the permanent file using native code instead
  of calling /bin/mv.  Hopefully this will permanently solve the
  (now rare) issue where netconfigs files disappear.
* Allow users to retrieve and store netconfigs files for their
  own mailbox rooms.  This will be required for configuration of
  POP3 aggregation, and in the future it will be required for
  RSS aggregation.

citadel/modules/network/serv_network.c

index 8e8847546ec5e2b8ca42da5689588894194cd8c3..7a7e54f584731a0d10f801ac45c5e69672f0b9c6 100644 (file)
@@ -366,7 +366,11 @@ void cmd_gnet(char *argbuf) {
        char buf[SIZ];
        FILE *fp;
 
-       if (CtdlAccessCheck(ac_room_aide)) return;
+       if ( (CC->room.QRflags & QR_MAILBOX) && (CC->user.usernum == atol(CC->room.QRname)) ) {
+               /* users can edit the netconfigs for their own mailbox rooms */
+       }
+       else if (CtdlAccessCheck(ac_room_aide)) return;
+
        assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
        cprintf("%d Network settings for room #%ld <%s>\n",
                LISTING_FOLLOWS,
@@ -389,11 +393,15 @@ void cmd_snet(char *argbuf) {
        char tempfilename[SIZ];
        char filename[SIZ];
        char buf[SIZ];
-       FILE *fp;
+       FILE *fp, *newfp;
 
        unbuffer_output();
 
-       if (CtdlAccessCheck(ac_room_aide)) return;
+       if ( (CC->room.QRflags & QR_MAILBOX) && (CC->user.usernum == atol(CC->room.QRname)) ) {
+               /* users can edit the netconfigs for their own mailbox rooms */
+       }
+       else if (CtdlAccessCheck(ac_room_aide)) return;
+
        CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
        assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
 
@@ -411,15 +419,23 @@ void cmd_snet(char *argbuf) {
        }
        fclose(fp);
 
-       /* Now copy the temp file to its permanent location
-        * (We use /bin/mv instead of link() because they may be on
-        * different filesystems)
+       /* Now copy the temp file to its permanent location.
+        * (We copy instead of link because they may be on different filesystems)
         */
-       unlink(filename);
-       snprintf(buf, sizeof buf, "/bin/mv %s %s", tempfilename, filename);
        begin_critical_section(S_NETCONFIGS);
-       system(buf);
+       fp = fopen(tempfilename, "r");
+       if (fp != NULL) {
+               newfp = fopen(filename, "w");
+               if (newfp != NULL) {
+                       while (fgets(buf, sizeof buf, fp) != NULL) {
+                               fprintf(newfp, "%s", buf);
+                       }
+                       fclose(newfp);
+                       fclose(fp);
+               }
+       }
        end_critical_section(S_NETCONFIGS);
+       unlink(tempfilename);
 }