Back to index

courier  0.68.2
token.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 
00007 /*
00008 */
00009 #include      "sqwebmail.h"
00010 #include      "config.h"
00011 #include      "token.h"
00012 #include      "sqconfig.h"
00013 #include      "cgi/cgi.h"
00014 #include      <stdio.h>
00015 #include      <string.h>
00016 #if    HAVE_UNISTD_H
00017 #include      <unistd.h>
00018 #endif
00019 #if     TIME_WITH_SYS_TIME
00020 #include        <sys/time.h>
00021 #include        <time.h>
00022 #else
00023 #if     HAVE_SYS_TIME_H
00024 #include        <sys/time.h>
00025 #else
00026 #include        <time.h>
00027 #endif
00028 #endif
00029 
00030 void tokennew()
00031 {
00032 time_t t;
00033 
00034        time(&t);
00035        printf("<input type=\"hidden\" name=\"msgtoken\" value=\"%ld-%ld\" />",
00036               (long)t, (long)getpid());
00037 }
00038 
00039 void tokennewget()
00040 {
00041 time_t t;
00042 
00043        time(&t);
00044        printf("&amp;msgtoken=%ld-%ld", (long)t, (long)getpid());
00045 }
00046 
00047 int tokencheck()
00048 {
00049 const char *token=cgi("msgtoken");
00050 const char *savedtoken;
00051 
00052        if (!token || token[0] == '\0')
00053               return(0);
00054        savedtoken=read_sqconfig(".", TOKENFILE, 0);
00055        if (savedtoken && strcmp(token, savedtoken) == 0)
00056               return (-1);
00057        return (0);
00058 }
00059 
00060 void tokensave()
00061 {
00062        write_sqconfig(".", TOKENFILE, cgi("msgtoken"));
00063 }
00064