Back to index

courier  0.68.2
Functions
pcpdauthtoken.h File Reference
#include "config.h"
#include <time.h>
#include <sys/time.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void authtoken_init ()
time_t authtoken_check ()
char * authtoken_create (const char *, time_t)
int authtoken_verify (const char *, const char *, time_t *)

Function Documentation

time_t authtoken_check ( )

Definition at line 168 of file pcpdauthtoken.c.

{
       time_t now;

       time(&now);

       if (now < expire_time && now >= expire_time - TIMEOUT*4)
              return (expire_time - now);

       memcpy(prev_token, cur_token, sizeof(cur_token));
       newtoken(cur_token);
       savetokens();
       now += TIMEOUT*2;
       expire_time=now;
       return (TIMEOUT*2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* authtoken_create ( const char *  ,
time_t   
)

Definition at line 191 of file pcpdauthtoken.c.

{
       return (mktoken(userid, cur_token, now));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void authtoken_init ( )

Definition at line 116 of file pcpdauthtoken.c.

{
       char buf1[512], buf2[512];
       char t1[128/8], t2[128/8];
       struct stat stat_buf;

       FILE *fp=fopen(RANDTOKENFILE, "r");

       time(&expire_time);

       if (fp)
       {
              if (fgets(buf1, sizeof(buf1), fp) &&
                  fgets(buf2, sizeof(buf2), fp))
              {
                     char *p;

                     if ((p=strchr(buf1, '\n')) != NULL)
                            *p=0;
                     if ((p=strchr(buf2, '\n')) != NULL)
                            *p=0;

                     /* Determine if the saved tokens are kosher */

                     if (strlen(buf1) == 32 &&
                         strlen(buf2) == 32 &&
                         goodtoken(buf1, t1) == 0 &&
                         goodtoken(buf2, t2) == 0 &&
                         fstat(fileno(fp), &stat_buf) == 0 &&

                         /* Haven't expired (+tolerate clock adjustments) */
                         stat_buf.st_mtime < expire_time + 60 &&
                         stat_buf.st_mtime >= expire_time - TIMEOUT*2)
                     {
                            expire_time=stat_buf.st_mtime + TIMEOUT*2;
                            memcpy(prev_token, t1, sizeof(t1));
                            memcpy(cur_token, t2, sizeof(t2));
                            fclose(fp);
                            fprintf(stderr, "NOTICE: restored saved authentication tokens\n");
                            return;
                     }
              }
              fclose(fp);
       }
       newtoken(prev_token);
       newtoken(cur_token);
       expire_time += TIMEOUT*2;
       savetokens();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int authtoken_verify ( const char *  ,
const char *  ,
time_t *   
)

Definition at line 250 of file pcpdauthtoken.c.

{
       time_t tval=0;
       const char *p=token;
       char *q;
       time_t now;

       while (*p)
       {
              int n=nyb(*p);

              if (n < 0)
                     break;

              tval *= 16;
              tval += n;
              ++p;
       }

       if (*p != '-' || p != token + sizeof(tval)*2)
              return (-1);

       time(&now);
       if (tval < now - TIMEOUT*4 || tval > now+60)
              return (-1);
       *when=tval;

       q=mktoken(userid, cur_token, tval);

       if (q)
       {
              if (strcmp(q, token) == 0)
              {
                     free(q);
                     return (0);
              }
              free(q);
              q=mktoken(userid, prev_token, tval);

              if (q)
              {
                     if (strcmp(q, token) == 0)
                     {
                            free(q);
                            return (0);
                     }
                     free(q);
                     return (-1);
              }
       }

       fprintf(stderr, "CRIT: authtoken_create() failed.\n");
       return (-1);
}

Here is the call graph for this function:

Here is the caller graph for this function: