1 /*
2 ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
3 ** distribution information.
4 */
5 
6 
7 /*
8 */
9 #include	"sqwebmail.h"
10 #include	"config.h"
11 #include	"token.h"
12 #include	"sqconfig.h"
13 #include	"cgi/cgi.h"
14 #include	<stdio.h>
15 #include	<string.h>
16 #if	HAVE_UNISTD_H
17 #include	<unistd.h>
18 #endif
19 #if     TIME_WITH_SYS_TIME
20 #include        <sys/time.h>
21 #include        <time.h>
22 #else
23 #if     HAVE_SYS_TIME_H
24 #include        <sys/time.h>
25 #else
26 #include        <time.h>
27 #endif
28 #endif
29 
tokennew()30 void tokennew()
31 {
32 time_t	t;
33 
34 	time(&t);
35 	printf("<input type=\"hidden\" name=\"msgtoken\" value=\"%ld-%ld\" />",
36 		(long)t, (long)getpid());
37 }
38 
tokennewget()39 void tokennewget()
40 {
41 time_t	t;
42 
43 	time(&t);
44 	printf("&amp;msgtoken=%ld-%ld", (long)t, (long)getpid());
45 }
46 
tokencheck()47 int tokencheck()
48 {
49 const char *token=cgi("msgtoken");
50 const char *savedtoken;
51 
52 	if (!token || token[0] == '\0')
53 		return(0);
54 	savedtoken=read_sqconfig(".", TOKENFILE, 0);
55 	if (savedtoken && strcmp(token, savedtoken) == 0)
56 		return (-1);
57 	return (0);
58 }
59 
tokensave()60 void tokensave()
61 {
62 	write_sqconfig(".", TOKENFILE, cgi("msgtoken"));
63 }
64 
65