* Eliminated the use of tmpnam() to shut up the compiler warnings.
authorArt Cancro <ajc@citadel.org>
Mon, 28 Nov 2005 02:21:04 +0000 (02:21 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 28 Nov 2005 02:21:04 +0000 (02:21 +0000)
13 files changed:
citadel/ChangeLog
citadel/citadel.c
citadel/messages.c
citadel/msgbase.c
citadel/room_ops.c
citadel/routines2.c
citadel/serv_calendar.c
citadel/serv_network.c
citadel/serv_vandelay.c
citadel/serv_vcard.c
citadel/setup.c
citadel/tools.c
citadel/tools.h

index 4db25d28024938e049a6b88ff42baaccd0bc9b4f..bdf12479e4c2866f2ba50f03c8cbe20fea081ede 100644 (file)
@@ -1,5 +1,8 @@
 $Id$
 
+Sun Nov 27 21:20:27 EST 2005 ajc
+* Eliminated the use of tmpnam() to shut up the compiler warnings.
+
 Mon Nov 21 16:59:43 CET 2005 dothebart
 * add some script to wrap the debian package build that does some magic about
   the versioning in the package and the citadel system
index 6d7b569cf93cde7e419e123dee822fb89b987c5f..84c4c1e453bd7460802f5230a4056ae252a61d2a 100644 (file)
@@ -1364,9 +1364,9 @@ NEWUSR:   if (strlen(rc_password) == 0) {
         * program.  Don't mess with these once they've been set, because we
         * will be unlinking them later on in the program and we don't
         * want to delete something that we didn't create. */
-       snprintf(temp, sizeof temp, tmpnam(NULL));
-       snprintf(temp2, sizeof temp2, tmpnam(NULL));
-       snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
+       CtdlMakeTempFileName(temp, sizeof temp);
+       CtdlMakeTempFileName(temp2, sizeof temp2);
+       CtdlMakeTempFileName(tempdir, sizeof tempdir);
 
        /* Get screen dimensions.  First we go to a default of 80x24.  Then
         * we try to get the user's actual screen dimensions off the server.
index 1bcf7add8f21b7bb5ea55cd4c28a2bd874ebed69..b71ca5d79ec2b4c1c5107d8bee1a2ddde51d0ffc 100644 (file)
@@ -1465,9 +1465,8 @@ void image_view(CtdlIPC *ipc, unsigned long msg)
                                        len = (size_t)extract_long(buf, 0);
                                        progress(ipc, len, len);
                                        scr_flush();
-                                       snprintf(tmp, sizeof tmp, "%s.%s",
-                                               tmpnam(NULL),
-                                               ptr->filename);
+                                       CtdlMakeTempFileName(tmp, sizeof tmp);
+                                       strcat(tmp, ptr->filename);
                                        save_buffer(file, len, tmp);
                                        free(file);
                                        do_image_view(tmp);
@@ -1510,7 +1509,7 @@ void readmsgs(CtdlIPC *ipc,
        else
                b = 0;
 
-       strcpy(prtfile, tmpnam(NULL));
+       CtdlMakeTempFileName(prtfile, sizeof prtfile);
 
        if (msg_arr) {
                free(msg_arr);
index 73269f3e05aabd0d3ffa8b7f972e2667769817db..c0e5eaa2ce1d110d48b89d15322bfd9d053a545a 100644 (file)
@@ -3537,12 +3537,12 @@ void CtdlWriteObject(char *req_room,            /* Room to stuff it in */
        char *encoded_message = NULL;
        off_t raw_length = 0;
 
-       if (is_mailbox != NULL)
+       if (is_mailbox != NULL) {
                MailboxName(roomname, sizeof roomname, is_mailbox, req_room);
-       else
+       }
+       else {
                safestrncpy(roomname, req_room, sizeof(roomname));
-       lprintf(CTDL_DEBUG, "CtdlWriteObject() to <%s> (flags=%d)\n", roomname, flags);
-
+       }
 
        fp = fopen(tempfilename, "rb");
        if (fp == NULL) {
@@ -3691,7 +3691,7 @@ void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) {
        char temp[PATH_MAX];
        FILE *fp;
 
-       strcpy(temp, tmpnam(NULL));
+       CtdlMakeTempFileName(temp, sizeof temp);
 
        fp = fopen(temp, "w");
        if (fp == NULL) return;
index 9e0e8f0b0f73b7de11fca87b17bb37473a8b8e8f..35adabbc383791c13b9d32996d25e4c07d6fb10a 100644 (file)
@@ -1083,7 +1083,7 @@ void cmd_rdir(void)
        char tempfilename[PATH_MAX];
 
        if (CtdlAccessCheck(ac_logged_in)) return;
-       tmpnam(tempfilename);
+       CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
        
        getroom(&CC->room, CC->room.QRname);
        getuser(&CC->user, CC->curr_user);
index 731586bef25638a291b7dd80219910cb6c168478..e2d9ee2b5bebd3a13ceffd53b467662b704a7839 100644 (file)
@@ -1046,8 +1046,8 @@ void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
                return;
        }
 
-       snprintf(filename, sizeof filename, "%s.listedit", tmpnam(NULL));
-       snprintf(changefile, sizeof changefile, "%s.listedit", tmpnam(NULL));
+       CtdlMakeTempFileName(filename, sizeof filename);
+       CtdlMakeTempFileName(changefile, sizeof changefile);
 
        tempfp = fopen(filename, "w");
        if (tempfp == NULL) {
index 2d8a3824091c6208660754bf72d29b21ce8f5914..527982072e37512c1ec92b9ff5cff0ca378fd5fa 100644 (file)
@@ -126,7 +126,7 @@ void ical_write_to_cal(struct ctdluser *u, icalcomponent *cal) {
                return;
        }
 
-       strcpy(temp, tmpnam(NULL));
+       CtdlMakeTempFileName(temp, sizeof temp);
        ser = icalcomponent_as_ical_string(cal);
        if (ser == NULL) return;
 
index 7ff3ea35a069ca251a9c5cced68ff7ca3f8aea96..b1c4c162f3285c642e091a7f7d1cfd9be9bba841 100644 (file)
@@ -390,7 +390,7 @@ void cmd_snet(char *argbuf) {
        unbuffer_output();
 
        if (CtdlAccessCheck(ac_room_aide)) return;
-       safestrncpy(tempfilename, tmpnam(NULL), sizeof tempfilename);
+       CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
        assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
 
        fp = fopen(tempfilename, "w");
@@ -1669,7 +1669,7 @@ void receive_spool(int sock, char *remote_nodename) {
        long plen;
        FILE *fp;
 
-       strcpy(tempfilename, tmpnam(NULL));
+       CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
        if (sock_puts(sock, "NDOP") < 0) return;
        if (sock_gets(sock, buf) < 0) return;
        lprintf(CTDL_DEBUG, "<%s\n", buf);
index 49f5ed9de98e8e6853d38b38694b06449f827729..501e5b74f5163d8d29074a5751f4945a589ae511 100644 (file)
@@ -193,7 +193,7 @@ void artv_export_message(long msgnum) {
        struct ser_ret smr;
        FILE *fp;
        char buf[SIZ];
-       char tempfile[SIZ];
+       char tempfile[PATH_MAX];
 
        msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;        /* fail silently */
@@ -208,7 +208,7 @@ void artv_export_message(long msgnum) {
        CtdlFreeMessage(msg);
 
        /* write it in base64 */
-       strcpy(tempfile, tmpnam(NULL));
+       CtdlMakeTempFileName(tempfile, sizeof tempfile);
        snprintf(buf, sizeof buf, "./base64 -e >%s", tempfile);
        fp = popen(buf, "w");
        fwrite(smr.ser, smr.len, 1, fp);
@@ -517,7 +517,7 @@ void artv_import_message(void) {
        long msglen;
        FILE *fp;
        char buf[SIZ];
-       char tempfile[SIZ];
+       char tempfile[PATH_MAX];
        char *mbuf;
 
        memset(&smi, 0, sizeof(struct MetaData));
@@ -529,7 +529,7 @@ void artv_import_message(void) {
        lprintf(CTDL_INFO, "message #%ld\n", msgnum);
 
        /* decode base64 message text */
-       strcpy(tempfile, tmpnam(NULL));
+       CtdlMakeTempFileName(tempfile, sizeof tempfile);
        snprintf(buf, sizeof buf, "./base64 -d >%s", tempfile);
        fp = popen(buf, "w");
        while (client_getln(buf, sizeof buf), strcasecmp(buf, END_OF_MESSAGE)) {
@@ -608,8 +608,8 @@ void cmd_artv(char *cmdbuf) {
        }
        is_running = 1;
 
-       strcpy(artv_tempfilename1, tmpnam(NULL));
-       strcpy(artv_tempfilename2, tmpnam(NULL));
+       CtdlMakeTempFileName(artv_tempfilename1, sizeof artv_tempfilename1);
+       CtdlMakeTempFileName(artv_tempfilename2, sizeof artv_tempfilename2);
 
        extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
        if (!strcasecmp(cmd, "export")) artv_do_export();
index a106a872f3a4ba7669ecc1cd8a70bc419faf5d72..24ab2199e12a9d1c444741179eff4e9fd3d54bce 100644 (file)
@@ -540,7 +540,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");
index 2cf23500528dec6f04d6e24ca7fe7cdc16ed3e4a..7d4edbc206215ee18cc24c0289930e37e18d0360 100644 (file)
@@ -718,7 +718,7 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
 #endif
        char buf[SIZ];
        char setupmsg[SIZ];
-       char *dialog_result;
+       char dialog_result[PATH_MAX];
        FILE *fp = NULL;
 
        strcpy(setupmsg, "");
@@ -736,7 +736,7 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
                break;
 
        case UI_DIALOG:
-               dialog_result = tmpnam(NULL);
+               CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
                sprintf(buf, "exec %s --backtitle '%s' --inputbox '%s' 19 72 '%s' 2>%s",
                        getenv("CTDL_DIALOG"),
                        prompt_title,
index 982d1ae1bee027edbbe5a3fa9d6fd08e2b16c08f..e8a1abc9798e04e57db37accbd21a087468dc4e0 100644 (file)
@@ -634,3 +634,20 @@ char *bmstrcasestr(char *text, char *pattern) {
 
 
 
+/*
+ * Local replacement for controversial C library function that generates
+ * names for temporary files.  Included to shut up compiler warnings.
+ */
+void CtdlMakeTempFileName(char *name, int len) {
+       int i = 0;
+
+       while (i++, i < 100) {
+               snprintf(name, len, "/tmp/ctdl.%04x.%04x",
+                       getpid(),
+                       rand()
+               );
+               if (!access(name, F_OK)) {
+                       return;
+               }
+       }
+}
index 41bfb94073db9815caacdd18af65d843a1108a39..01c196b2b3f36ad9d0d8f45e5757c2ecde2884dd 100644 (file)
@@ -32,3 +32,4 @@ FILE *CtdlTempFile(void);
 char *ascmonths[12];
 void generate_uuid(char *buf);
 char *bmstrcasestr(char *text, char *pattern);
+void CtdlMakeTempFileName(char *name, int len);