Back to index

courier  0.68.2
Classes | Functions
tlsclient.h File Reference
#include "config.h"
#include <sys/types.h>
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tls_subjitem
struct  tls_subject
struct  couriertls_info

Functions

void couriertls_init (struct couriertls_info *)
int couriertls_start (char **, struct couriertls_info *)
const char * couriertls_get_subject (struct couriertls_info *, const char *subject)
void couriertls_export_subject_environment (struct couriertls_info *)
void couriertls_destroy (struct couriertls_info *)

Class Documentation

struct tls_subjitem

Definition at line 18 of file tlsclient.h.

Collaboration diagram for tls_subjitem:
Class Members
const char * name
struct tls_subjitem * nextitem
const char * value
struct tls_subject

Definition at line 24 of file tlsclient.h.

Collaboration diagram for tls_subject:
Class Members
struct tls_subjitem * firstitem
struct tls_subject * next
struct couriertls_info

Definition at line 29 of file tlsclient.h.

Collaboration diagram for couriertls_info:
Class Members
int bits
const char * cipher
char errmsg
struct tls_subject * first_subject
const char * version
char * x509info
size_t x509info_len
size_t x509info_size

Function Documentation

void couriertls_destroy ( struct couriertls_info )

Definition at line 486 of file tlsclient.c.

{
       struct tls_subject *subj;
       struct tls_subjitem *subjitem;

       if (info->x509info)
              free(info->x509info);

       while ((subj=info->first_subject) != 0)
       {
              info->first_subject=subj->next;
              while ((subjitem=subj->firstitem) != 0)
              {
                     subj->firstitem=subjitem->nextitem;
                     free(subjitem);
              }
              free(subj);
       }
}

Here is the caller graph for this function:

Definition at line 253 of file tlsclient.c.

{
       struct tls_subject *subj;
       struct tls_subjitem *item;

       if ((subj=cinfo->first_subject) == 0)
              return;

       for (item=subj->firstitem; item; item=item->nextitem)
       {
              char *a=malloc(strlen(item->name)+20);
              const char *b=item->value;
              char *p;

              if (!a) continue;

              strcat(strcpy(a, "TLS_SUBJECT_"), item->name);

              for (p=a; *p; p++)
                     if (*p >= 'a' && *p <= 'z')
                            *p -= 'a' - 'A';

              setenv(a, b, 1);
              free(a);
       }
}

Here is the caller graph for this function:

const char* couriertls_get_subject ( struct couriertls_info ,
const char *  subject 
)

Definition at line 207 of file tlsclient.c.

{
       struct tls_subject *subj;
       struct tls_subjitem *item, *p;

       if ((subj=cinfo->first_subject) == 0)
              return NULL;

       p=NULL;

       for (item=subj->firstitem; item; item=item->nextitem)
       {
              const char *a=item->name;
              const char *b=subject;

              while (*a && *b)
              {
                     int ca= *a++;
                     int cb= *b++;

                     /* Locale muddies things up, do this by hand */

                     if (ca >= 'a' && ca <= 'z')
                            ca -= 'a' - 'A';

                     if (cb >= 'a' && cb <= 'z')
                            cb -= 'a' - 'A';

                     if (ca != cb)
                            break;
              }

              if (!*a && !*b)
                     p=item;
              /*
              ** We want the last one, to match the behavior when couriertls
              ** passes this stuff via the environment.
              */
       }

       if (p)
              return p->value;
       return (0);
}

Here is the call graph for this function:

void couriertls_init ( struct couriertls_info )

Definition at line 62 of file tlsclient.c.

{
       memset(cinfo, 0, sizeof(*cinfo));
       cinfo->cipher=cinfo->version="Unknown";
}

Here is the caller graph for this function:

int couriertls_start ( char **  ,
struct couriertls_info  
)

Definition at line 75 of file tlsclient.c.

{
       int rc=do_couriertls_start(args, cinfo);
       int l;
       char *p;

       if (rc && cinfo->errmsg[0] == 0)
              strcpy(cinfo->errmsg, "Failed to initialize TLS/SSL\n");

       l=strlen(cinfo->errmsg);

       while (l > 0 && cinfo->errmsg[l-1] == '\n')
              --l;
       cinfo->errmsg[l]=0;

       if (rc || cinfo->x509info == 0)
              return (rc);

       cinfo->x509info[cinfo->x509info_len]=0;
       p=strtok(cinfo->x509info, "\r\n");

       while (p)
       {
              int i;

              for (i=0; p[i]; i++)
                     if (!isalpha(p[i]))
                            break;

              if (p[i] != ':')
              {
                     p=strtok(NULL, "\r\n");
                     continue;
              }
              p[i++]=0;

              /*
              ** IMPORTANT: UCase *MUST* match the output of couriertls.
              ** I'd love to use strcasecmp, here, but certain glibc
              ** locale break the standard case of lower ascii chset
              ** range.
              */

              if (strcmp(p, "Subject") == 0)
              {
                     struct tls_subject *subj, *subj2;
                     struct tls_subjitem **itemptr;

                     p += i;

                     for (subj=cinfo->first_subject; subj && subj->next;
                          subj=subj->next)
                            ;

                     subj2=(struct tls_subject *)
                            malloc(sizeof(struct tls_subject));
                     if (!subj2)
                     {
                            SYSERRMSG;
                            return (-1);
                     }

                     if (subj)
                            subj->next=subj2;
                     else
                            cinfo->first_subject=subj2;

                     subj2->next=0;
                     subj2->firstitem=0;
                     itemptr= &subj2->firstitem;

                     while ( p && (*p == 0
                                  || isspace((int)(unsigned char)*p)))
                     {
                            while (*p && isspace((int)(unsigned char)*p))
                                   ++p;
                            for (i=0; p[i]; i++)
                                   if (!isalpha((int)(unsigned char)p[i]))
                                          break;
                            if (p[i] != '=')
                            {
                                   p=strtok(NULL, "\r\n");
                                   continue;
                            }
                            p[i++]=0;

                            *itemptr= (struct tls_subjitem *)
                                   malloc(sizeof (struct tls_subjitem));

                            if (!*itemptr)
                            {
                                   SYSERRMSG;
                                   return (-1);
                            }

                            (*itemptr)->name=p;
                            (*itemptr)->value=p+i;
                            (*itemptr)->nextitem=0;

                            itemptr= &(*itemptr)->nextitem;
                            p=strtok(NULL, "\r\n");
                     }
                     continue;
              }

              if (strcmp(p, "Cipher") == 0)
              {
                     p += i;
                     while (*p && isspace((int)(unsigned char)*p))
                            ++p;
                     cinfo->cipher=p;
              }
              else if (strcmp(p, "Version") == 0)
              {
                     p += i;
                     while (*p && isspace((int)(unsigned char)*p))
                            ++p;
                     cinfo->version=p;
              }
              else if (strcmp(p, "Bits") == 0)
              {
                     p += i;
                     while (*p && isspace((int)(unsigned char)*p))
                            ++p;
                     cinfo->bits=atoi(p);
              }
              p=strtok(NULL, "\r\n");
       }

       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function: