tmpnam(). Rewrote using tmpfile() where possible.
+Wed Jun 9 23:34:25 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+ * Replaced all code that generated temporary filenames with calls to
+ tmpnam(). Rewrote using tmpfile() where possible.
+
Thu Jun 3 11:35:18 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
* base64.c: mapped fi and fo to stdin and stdout using
actual code rather than assignment at declaration time
int main(int argc, char **argv)
{
- char tempbase[32];
- char temptmp[64];
char tempspool[64];
char target_room[ROOMNAMELEN];
FILE *tempfp, *spoolfp;
}
- snprintf(tempbase, sizeof tempbase, "ap.%d", getpid());
- snprintf(temptmp, sizeof temptmp, "/tmp/%s", tempbase);
- snprintf(tempspool, sizeof tempspool, "./network/spoolin/%s", tempbase);
+ snprintf(tempspool, sizeof tempspool, "./network/spoolin/ap.%d",
+ getpid());
- tempfp = fopen(temptmp, "wb+");
+ tempfp = tmpfile();
if (tempfp == NULL) {
perror("cannot open temp file");
exit(errno);
}
- /* Unlink the temp file, so it automatically gets deleted by the OS if
- * this program is interrupted or crashes.
- */ unlink(temptmp);
/* Generate a message from stdin */
make_message(tempfp, target_room);
#include <ctype.h>
#include <string.h>
#include <time.h>
+#include <limits.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
struct march *march = NULL;
/* globals associated with the client program */
-char temp[16]; /* Name of general temp file */
-char temp2[16]; /* Name of general temp file */
-char tempdir[16]; /* Name of general temp dir */
+char temp[PATH_MAX]; /* Name of general temp file */
+char temp2[PATH_MAX]; /* Name of general temp file */
+char tempdir[PATH_MAX]; /* Name of general temp dir */
char editor_path[256]; /* path to external editor */
char printcmd[256]; /* print command */
int editor_pid = (-1);
* 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, "/tmp/citA%d", getpid());
- snprintf(temp2, sizeof temp2, "/tmp/citB%d", getpid());
- snprintf(tempdir, sizeof tempdir, "/tmp/citC%d", getpid());
+ snprintf(temp, sizeof temp, tmpnam(NULL));
+ snprintf(temp2, sizeof temp2, tmpnam(NULL));
+ snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
/* 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.
strcpy(CC->cs_clientname, "(unknown)");
strcpy(CC->curr_user,"(not logged in)");
strcpy(CC->net_node,"");
- snprintf(CC->temp, sizeof CC->temp, "/tmp/CitServer.%d.%d", getpid(), CC->cs_pid);
+ snprintf(CC->temp, sizeof CC->temp, tmpnam(NULL));
strcpy(CC->cs_room, "(no room)");
strncpy(CC->cs_host, config.c_fqdn, sizeof CC->cs_host);
CC->cs_host[sizeof CC->cs_host - 1] = 0;
struct config config;
-main(argc,argv)
+main(argc, argv)
int argc;
-char *argv[]; {
+char *argv[];
+{
struct tm *tm;
- int a,b,e,mtype,aflag;
- char bbb[100],ngn[100];
+ int a, b, e, mtype, aflag;
+ char bbb[100], ngn[100];
long tmid;
char tsid[64];
char tuid[64];
- FILE *fp,*tfp;
- long now,msglen;
- char tflnm[16];
+ FILE *fp, *tfp;
+ long now, msglen;
int cuunbatch = 0;
/* experimental cuunbatch header generation */
- for (a=0; a<argc; ++a) {
- if (!strcmp(argv[a],"-c")) cuunbatch = 1;
- }
+ for (a = 0; a < argc; ++a) {
+ if (!strcmp(argv[a], "-c"))
+ cuunbatch = 1;
+ }
get_config();
- snprintf(tflnm,sizeof tflnm,"/tmp/c2a%d",getpid());
-
- fp=stdin;
- while (1) {
- do {
- e=getc(fp);
- if (e<0) exit(0);
- } while(e!=255);
- mtype=getc(fp); aflag=getc(fp);
-
- tmid = 0L;
- strcpy(tsid,FQDN);
- strcpy(tuid,"postmaster");
-
- tfp=fopen(tflnm,"w");
- do {
- b=getc(fp);
- if (b=='M') {
- fprintf(tfp,"Message-ID: <%ld@%s>\n",tmid,tsid);
- fprintf(tfp,"\n");
- if (aflag!=1) fmout(80,fp,tfp);
- else while(a=getc(fp), a>0) {
- putc(a,tfp); if (a==13) putc(10,tfp);
+ fp = stdin;
+ while (1) {
+ do {
+ e = getc(fp);
+ if (e < 0)
+ exit(0);
+ } while (e != 255);
+ mtype = getc(fp);
+ aflag = getc(fp);
+
+ tmid = 0L;
+ strcpy(tsid, FQDN);
+ strcpy(tuid, "postmaster");
+
+ tfp = tmpfile();
+ do {
+ b = getc(fp);
+ if (b == 'M') {
+ fprintf(tfp, "Message-ID: <%ld@%s>\n", tmid, tsid);
+ fprintf(tfp, "\n");
+ if (aflag != 1)
+ fmout(80, fp, tfp);
+ else
+ while (a = getc(fp), a > 0) {
+ putc(a, tfp);
+ if (a == 13)
+ putc(10, tfp);
+ }
}
- }
- if ((b!='M')&&(b>0)) fpgetfield(fp,bbb);
- if (b=='I') tmid=atol(bbb);
- if (b=='N') {
- strcpy(tsid,bbb);
- if (!strcmp(tsid,NODENAME)) strcpy(tsid,FQDN);
- for (a=0; a<strlen(tuid); ++a) if (tuid[a]==' ') tuid[a]='_';
- fprintf(tfp,"From: %s@%s ",tuid,tsid);
- for (a=0; a<strlen(tuid); ++a) if (tuid[a]=='_') tuid[a]=' ';
- fprintf(tfp,"(%s)\n",tuid);
- }
- if (b=='P') fprintf(tfp,"Path: %s\n",bbb);
- if (b=='A') strcpy(tuid,bbb);
- if (b=='O') {
- xref(bbb,ngn);
- fprintf(tfp,"Newsgroups: %s\n",ngn);
- }
- if (b=='R') fprintf(tfp,"To: %s\n",bbb);
- if (b=='U') fprintf(tfp,"Subject: %s\n",bbb);
- if (b=='T') {
- now=atol(bbb);
- tm=(struct tm *)localtime(&now);
- fprintf(tfp,"Date: %s",asctime(tm));
- }
- } while ((b!='M')&&(b>0));
- msglen=ftell(tfp);
- fclose(tfp);
+ if ((b != 'M') && (b > 0))
+ fpgetfield(fp, bbb);
+ if (b == 'I')
+ tmid = atol(bbb);
+ if (b == 'N') {
+ strcpy(tsid, bbb);
+ if (!strcmp(tsid, NODENAME))
+ strcpy(tsid, FQDN);
+ for (a = 0; a < strlen(tuid); ++a)
+ if (tuid[a] == ' ')
+ tuid[a] = '_';
+ fprintf(tfp, "From: %s@%s ", tuid, tsid);
+ for (a = 0; a < strlen(tuid); ++a)
+ if (tuid[a] == '_')
+ tuid[a] = ' ';
+ fprintf(tfp, "(%s)\n", tuid);
+ }
+ if (b == 'P')
+ fprintf(tfp, "Path: %s\n", bbb);
+ if (b == 'A')
+ strcpy(tuid, bbb);
+ if (b == 'O') {
+ xref(bbb, ngn);
+ fprintf(tfp, "Newsgroups: %s\n", ngn);
+ }
+ if (b == 'R')
+ fprintf(tfp, "To: %s\n", bbb);
+ if (b == 'U')
+ fprintf(tfp, "Subject: %s\n", bbb);
+ if (b == 'T') {
+ now = atol(bbb);
+ tm = (struct tm *) localtime(&now);
+ fprintf(tfp, "Date: %s", asctime(tm));
+ }
+ } while ((b != 'M') && (b > 0));
+ msglen = ftell(tfp);
- if (cuunbatch) {
- printf("#! cuunbatch %ld\n",msglen);
- }
- else {
- printf("#! rnews %ld\n",msglen);
+ if (cuunbatch) {
+ printf("#! cuunbatch %ld\n", msglen);
+ } else {
+ printf("#! rnews %ld\n", msglen);
}
- tfp=fopen(tflnm,"r");
- while(msglen--) putc(getc(tfp),stdout);
- fclose(tfp);
- unlink(tflnm);
- }
-exit(0);
+ rewind(tfp);
+ while (msglen--)
+ putc(getc(tfp), stdout);
+ fclose(tfp);
+ }
+ exit(0);
}
-fpgetfield(fp,string) /* level-2 break out next null-terminated string */
+fpgetfield(fp, string) /* level-2 break out next null-terminated string */
FILE *fp;
char string[];
{
-int a,b;
-strcpy(string,"");
-a=0;
+ int a, b;
+ strcpy(string, "");
+ a = 0;
do {
- b=getc(fp);
- if (b<1) { string[a]=0; return(0); }
- string[a]=b;
+ b = getc(fp);
+ if (b < 1) {
+ string[a] = 0;
+ return (0);
+ }
+ string[a] = b;
++a;
- } while(b!=0);
- return(0);
+ } while (b != 0);
+ return (0);
}
-fmout(width,fp,mout)
+fmout(width, fp, mout)
int width;
-FILE *fp,*mout;
- {
- int a,b,c,real,old;
+FILE *fp, *mout;
+{
+ int a, b, c, real, old;
char aaa[140];
-
- strcpy(aaa,""); old=255;
- c=1; /* c is the current pos */
-FMTA: old=real; a=getc(fp); real=a;
- if (a<=0) goto FMTEND;
-
- if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
- if ( ((old==13)||(old==10)) && (isspace(real)) ) {
- fprintf(mout,"\n"); c=1; }
- if (a>126) goto FMTA;
-
- if (a>32) {
- if ( ((strlen(aaa)+c)>(width-1)) && (strlen(aaa)>(width-1)) )
- { fprintf(mout,"\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
- b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
- if (a==32) { if ((strlen(aaa)+c)>(width-1)) {
- fprintf(mout,"\n");
- c=1;
- }
- fprintf(mout,"%s ",aaa); ++c; c=c+strlen(aaa);
- strcpy(aaa,""); goto FMTA; }
- if ((a==13)||(a==10)) {
- fprintf(mout,"%s\n",aaa); c=1;
- strcpy(aaa,""); goto FMTA; }
+
+ strcpy(aaa, "");
+ old = 255;
+ c = 1; /* c is the current pos */
+ FMTA:old = real;
+ a = getc(fp);
+ real = a;
+ if (a <= 0)
+ goto FMTEND;
+
+ if (((a == 13) || (a == 10)) && (old != 13) && (old != 10))
+ a = 32;
+ if (((old == 13) || (old == 10)) && (isspace(real))) {
+ fprintf(mout, "\n");
+ c = 1;
+ }
+ if (a > 126)
+ goto FMTA;
+
+ if (a > 32) {
+ if (((strlen(aaa) + c) > (width - 1)) && (strlen(aaa) > (width - 1))) {
+ fprintf(mout, "\n%s", aaa);
+ c = strlen(aaa);
+ aaa[0] = 0;
+ }
+ b = strlen(aaa);
+ aaa[b] = a;
+ aaa[b + 1] = 0;
+ }
+ if (a == 32) {
+ if ((strlen(aaa) + c) > (width - 1)) {
+ fprintf(mout, "\n");
+ c = 1;
+ }
+ fprintf(mout, "%s ", aaa);
+ ++c;
+ c = c + strlen(aaa);
+ strcpy(aaa, "");
+ goto FMTA;
+ }
+ if ((a == 13) || (a == 10)) {
+ fprintf(mout, "%s\n", aaa);
+ c = 1;
+ strcpy(aaa, "");
+ goto FMTA;
+ }
goto FMTA;
-FMTEND: fprintf(mout,"\n");
- return(0);
+ FMTEND:fprintf(mout, "\n");
+ return (0);
}
-xref(roomname,newsgroup)
-char *roomname,*newsgroup; {
+xref(roomname, newsgroup)
+char *roomname, *newsgroup;
+{
char tbuf[128];
FILE *fp;
- int commapos,a;
-
- strcpy(newsgroup,roomname);
- fp=fopen("./network/rnews.xref","r");
- if (fp==NULL) return(1);
- while (fgets(tbuf,128,fp)!=NULL) {
- tbuf[strlen(tbuf)-1]=0; /* strip off the newline */
- a=strlen(tbuf);
- while (a--) if (tbuf[a]==',') commapos=a;
- tbuf[commapos]=0;
- if (!strcasecmp(&tbuf[commapos+1],roomname))
- strcpy(newsgroup,tbuf);
- }
- fclose(fp);
- return(0);
+ int commapos, a;
+
+ strcpy(newsgroup, roomname);
+ fp = fopen("./network/rnews.xref", "r");
+ if (fp == NULL)
+ return (1);
+ while (fgets(tbuf, 128, fp) != NULL) {
+ tbuf[strlen(tbuf) - 1] = 0; /* strip off the newline */
+ a = strlen(tbuf);
+ while (a--)
+ if (tbuf[a] == ',')
+ commapos = a;
+ tbuf[commapos] = 0;
+ if (!strcasecmp(&tbuf[commapos + 1], roomname))
+ strcpy(newsgroup, tbuf);
}
+ fclose(fp);
+ return (0);
+}
get_config();
LoadInternetConfig();
- sprintf(tempfile, "/tmp/mlist.%ld", (long)getpid() );
+ sprintf(tempfile, tmpnam(NULL));
while(1) {
#include <time.h>
#include <signal.h>
#include <errno.h>
+#include <limits.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <stdarg.h>
char arcflag = 0;
char quotflag = 0;
int hold_color = 0;
- char prtfile[16];
+ char prtfile[PATH_MAX];
char pagin;
char cmd[256];
char targ[ROOMNAMELEN];
if (c<0) b=(MAXMSGS-1);
else b=0;
- sprintf(prtfile,"/tmp/CPrt%ld",(long)getpid());
+ sprintf(prtfile, tmpnam(NULL));
num_msgs = 0;
strcpy(cmd,"MSGS ");
enable_color = hold_color;
f=fork();
if (f==0) {
- freopen(prtfile,"r",stdin);
+ freopen(prtfile, "r", stdin);
sttybbs(SB_RESTORE);
ka_system(printcmd);
sttybbs(SB_NO_INTR);
void mime_download(char *name, char *filename, char *partnum, char *disp,
void *content, char *cbtype, size_t length) {
- char tmpname[PATH_MAX];
- static int seq = 0;
-
/* Silently go away if there's already a download open... */
if (CC->download_fp != NULL) return;
/* ...or if this is not the desired section */
if (strcasecmp(desired_section, partnum)) return;
- snprintf(tmpname, sizeof tmpname,
- "/tmp/CitServer.download.%4x.%4x", getpid(), ++seq);
-
- CC->download_fp = fopen(tmpname, "wb+");
+ CC->download_fp = tmpfile();
if (CC->download_fp == NULL) return;
- /* Unlink the file while it's open, to guarantee that the
- * temp file will always be deleted.
- */
- unlink(tmpname);
-
fwrite(content, length, 1, CC->download_fp);
fflush(CC->download_fp);
rewind(CC->download_fp);
#include <time.h>
#include <string.h>
#include <ctype.h>
+#include <limits.h>
#include <syslog.h>
#include "citadel.h"
void get_config(void);
struct config config;
-char temp[32];
+char temp[PATH_MAX];
char ALIASES[128];
char CIT86NET[128];
openlog("netmailer", LOG_PID, LOG_USER);
get_config();
LoadInternetConfig();
- sprintf(temp,"/tmp/netmailer.%ld",(long)getpid()); /* temp file name */
+ sprintf(temp, tmpnam(NULL)); /* temp file name */
if ( (argc < 2) || (argc > 3) ) {
fprintf(stderr, "netmailer: usage: netmailer recipient@node.dom [mlist]\n");
}
/* convert to ASCII & get info */
- fp=fopen(temp,"w");
+ fp=fopen(temp, "w");
msgform(argv[1], fp, sbuf, rbuf, nbuf, pbuf, &mid_buf, rmname, subject);
fclose(fp);
#include <fcntl.h>
#include <string.h>
#include <errno.h>
+#include <limits.h>
#include "citadel.h"
#include "tools.h"
long bytes_received;
char buf[256];
static char pbuf[IGNET_PACKET_SIZE];
- char tempfilename[64];
+ char tempfilename[PATH_MAX];
long plen;
FILE *fp;
- sprintf(tempfilename, "/tmp/netpoll.%ld", (long) getpid());
+ sprintf(tempfilename, tmpnam(NULL));
serv_puts("NDOP");
serv_gets(buf);
printf("%s\n", buf);
char insys = 0;
char buf[128];
- fp=fopen("network/mail.sysinfo","rb");
+ fp=fopen("network/mail.sysinfo", "r");
if (fp==NULL) return(1);
while(1) {
long msglen;
int bloklen;
-
- sprintf(tname,"/tmp/net.t%ld",(long)getpid()); /* temp file name */
- sprintf(iname,"/tmp/net.i%ld",(long)getpid()); /* temp file name */
+ /* temp file names */
+ sprintf(tname, tmpnam(NULL));
+ sprintf(iname, tmpnam(NULL));
load_filterlist();
} while((a!=255)&&(a>=0));
if (a<0) goto ENDSTR;
- message = fopen(tname,"wb"); /* This crates the temporary file. */
+ message = fopen(tname, "wb"); /* This crates the temporary file. */
if (message == NULL) {
syslog(LOG_ERR, "error creating %s: %s", tname,strerror(errno));
goto ENDSTR;
return(ok);
}
-int spool_out(struct msglist *cmlist, FILE *destfp, char *sysname) /* spool list of messages to a file */
- /* returns # of msgs spooled */
-
-
+
+
+/* spool list of messages to a file */
+/* returns # of msgs spooled */
+int spool_out(struct msglist *cmlist, FILE *destfp, char *sysname)
{
struct msglist *cmptr;
FILE *mmfp;
- char mmtemp[128];
char fbuf[128];
int a;
int msgs_spooled = 0;
char curr_rm[256];
strcpy(curr_rm, "");
- sprintf(mmtemp, "/tmp/net.m%ld", (long)getpid());
/* for each message in the list... */
for (cmptr=cmlist; cmptr!=NULL; cmptr=cmptr->next) {
}
/* download the message from the server... */
- mmfp = fopen(mmtemp, "wb");
+ mmfp = tmpfile();
sprintf(buf, "MSG3 %ld", cmptr->m_num);
serv_puts(buf);
serv_gets(buf);
else { /* or print the err */
syslog(LOG_ERR, "%s", buf);
}
- fclose(mmfp);
-
- mmfp = fopen(mmtemp,"rb");
+
+ rewind(mmfp);
if (ismsgok(0L,mmfp,sysname)) {
++msgs_spooled;
fclose(mmfp);
}
- unlink(mmtemp);
return(msgs_spooled);
}
int outgoing_msgs;
long thismsg;
- sprintf(tempflnm,"/tmp/%s.%ld",NODENAME,(long)getpid());
- tempflfp=fopen(tempflnm,"w");
- if (tempflfp==NULL) return;
+ sprintf(tempflnm, tmpnam(NULL));
+ tempflfp = fopen(tempflnm,"w");
+ if (tempflfp == NULL) return;
/*
char spool_only = 0;
get_config();
- sprintf(flnm,"./network/spoolin/rnews.%ld",(long)getpid());
- sprintf(tname,"/tmp/rnews.%ld",(long)getpid());
+ sprintf(flnm,"./network/spoolin/rnews.%d", getpid());
+ sprintf(tname, tmpnam(NULL));
for (a=1; a<argc; ++a) {
if (!strcmp(argv[a],"-c")) binary_input = 1;
char tempfile[64];
FILE *fp;
- sprintf(tempfile, "/tmp/setup.%ld", (long) getpid());
+ sprintf(tempfile, tmpnam(NULL));
switch (setup_type) {
case UI_TEXT: