Back to index

courier  0.68.2
Functions
gpg.h File Reference
#include <stdlib.h>
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void gpglistpub ()
void gpglistsec ()
void gpgcreate ()
void gpgdo ()
void gpgselectkey ()
void gpgencryptkeys (const char *)
int gpgbadarg (const char *)
void gpgselectpubkey ()
void gpgselectprivkey ()
int gpgexportkey (const char *, int, int(*)(const char *, size_t, void *), void *)
int gpgdomsg (int, int, const char *, const char *)
int gpgdecode (int, int)

Function Documentation

int gpgbadarg ( const char *  )

Definition at line 65 of file gpg.c.

{
       for ( ; *p; p++)
       {
              int c=(unsigned char)*p;

              if (c < ' ' || strchr("\",'`;*?()<>", c))
                     return (1);
       }
       return (0);
}

Here is the caller graph for this function:

void gpgcreate ( )

Definition at line 333 of file gpg.c.

{
       int linelen;

       const char *newname=cgi("newname");
       const char *newaddress=cgi("newaddress");
       const char *newcomment=cgi("newcomment");
       unsigned skl=atoi(cgi("skeylength"));
       unsigned ekl=atoi(cgi("ekeylength"));
       unsigned newexpire=atoi(cgi("newexpire"));
       char newexpirewhen=*cgi("newexpirewhen");
       const char *passphrase, *p;

       if (*newname == 0 || *newaddress == 0 || strchr(newaddress, '@') == 0
           || gpgbadarg(newname) || gpgbadarg(newaddress)
           || gpgbadarg(newcomment)
           || ekl < 512 || ekl > 2048 || skl < 512 || skl > 1024)
       {
              printf("%s\n", getarg("BADARGS"));
              return;
       }
       passphrase=cgi("passphrase");
       if (strcmp(passphrase, cgi("passphrase2")))
       {
              printf("%s\n", getarg("PASSPHRASEFAIL"));
              return;
       }

       for (p=passphrase; *p; p++)
       {
              if ((int)(unsigned char)*p < ' ')
              {
                     printf("%s\n", getarg("PASSPHRASEFAIL"));
                     return;
              }
       }

       printf("<pre class=\"gpgcreate\">");

       linelen=0;

       libmail_gpg_genkey(GPGDIR, sqwebmail_content_charset,
                        newname, newaddress, newcomment,
                        skl, ekl,
                        newexpire, newexpirewhen,
                        passphrase,
                        &dump_func,
                        &timeout_func,
                        &linelen);
       printf("</pre>");
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gpgdecode ( int  ,
int   
)

Definition at line 665 of file gpg.c.

{
       char passfd_buf[NUMBUFSIZE];
       FILE *fp=passphrasefp();
       int in_dup, out_dup;
       FILE *in_fp, *out_fp;
       struct libmail_gpg_info gi;
       char *argvec[2];
       int i;

       gpginiterr();

       if ((in_dup=dup(in_fd)) < 0 || (in_fp=fdopen(in_dup, "r")) == NULL)
       {
              if (in_dup >= 0)
                     close(in_dup);
              fclose(fp);
              enomem();
              return 1;
       }

       if ((out_dup=dup(out_fd)) < 0 || (out_fp=fdopen(out_dup, "w")) == NULL)
       {
              if (out_dup >= 0)
                     close(out_dup);
              fclose(in_fp);
              close(in_dup);
              fclose(fp);
              enomem();
              return 1;
       }

       memset(&gi, 0, sizeof(gi));

       gi.gnupghome=GPGDIR;
       if (fp)
       {
              gi.passphrase_fd=libmail_str_size_t(fileno(fp), passfd_buf);
       }

       gi.input_func= read_fd;
       gi.input_func_arg= in_fp;
       gi.output_func= write_fd;
       gi.output_func_arg= out_fp;
       gi.errhandler_func= gpg_error_save;
       gi.errhandler_arg= NULL;

       argvec[0] = "--no-tty";
       argvec[1]=NULL;
       gi.argc=1;
       gi.argv=argvec;

       i=libmail_gpg_decode(LIBMAIL_GPG_UNENCRYPT|LIBMAIL_GPG_CHECKSIGN,
                          &gi);
       fclose(out_fp);
       close(out_dup);
       fclose(in_fp);
       close(in_dup);
       if (fp)
              fclose(fp);

       if (i)
       {
              printf("<div class=\"indent\"><pre style=\"color: red;\">");
              sent_gpgerrtxt();
              printf("</pre></div>\n");
       }
       return (i);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gpgdo ( )

Definition at line 469 of file gpg.c.

{
       if (*cgi("delpub"))
              delkey(cgi("pubkeyname"), 0);
       else if (*cgi("delsec") && *cgi("really"))
              delkey(cgi("seckeyname"), 1);
       else if (*cgi("sign"))
              signkey(cgi("pubkeyname"), cgi("seckeyname"),
                     cgi("signlevel"));
       else if (*cgi("setdefault"))
              setdefault(cgi("seckeyname"));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gpgdomsg ( int  ,
int  ,
const char *  ,
const char *   
)

Definition at line 524 of file gpg.c.

{
       char *k=strdup(encryptkeys ? encryptkeys:"");
       int n;
       int i;
       char *p;
       char **argvec;
       FILE *passfd=NULL;
       char passfd_buf[NUMBUFSIZE];
       struct libmail_gpg_info gi;

       int in_dup, out_dup;
       FILE *in_fp, *out_fp;

       gpginiterr();

       if (!k)
       {
              enomem();
              return 1;
       }

       if ((in_dup=dup(in_fd)) < 0 || (in_fp=fdopen(in_dup, "r")) == NULL)
       {
              if (in_dup >= 0)
                     close(in_dup);
              free(k);
              enomem();
              return 1;
       }

       if ((out_dup=dup(out_fd)) < 0 || (out_fp=fdopen(out_dup, "w")) == NULL)
       {
              if (out_dup >= 0)
                     close(out_dup);
              fclose(in_fp);
              close(in_dup);
              free(k);
              enomem();
              return 1;
       }

       passfd=passphrasefp();

       n=0;
       for (p=k; (p=strtok(p, " ")) != NULL; p=NULL)
              ++n;

       argvec=malloc((n * 2 + 22)*sizeof(char *));
       if (!argvec)
       {
              fclose(out_fp);
              close(out_dup);
              fclose(in_fp);
              close(in_dup);
              free(k);
              enomem();
              return 1;
       }

       memset(&gi, 0, sizeof(gi));

       gi.gnupghome=GPGDIR;
       if (passfd)
       {
              gi.passphrase_fd=libmail_str_size_t(fileno(passfd),
                                              passfd_buf);
       }

       gi.input_func= read_fd;
       gi.input_func_arg= in_fp;
       gi.output_func= write_fd;
       gi.output_func_arg= out_fp;
       gi.errhandler_func= gpg_error_save;
       gi.errhandler_arg= NULL;


       i=0;
       argvec[i++] = "--no-tty";
       if (signkey)
       {
              argvec[i++]="--default-key";
              argvec[i++]=(char *)signkey;
       }

       argvec[i++]="--always-trust";

       for (p=strcpy(k, encryptkeys ? encryptkeys:"");
            (p=strtok(p, " ")) != NULL; p=NULL)
       {
              argvec[i++]="-r";
              argvec[i++]=p;
       }
       argvec[i]=0;
       gi.argc=i;
       gi.argv=argvec;

       i=libmail_gpg_signencode(signkey ? 1:0,
                             n > 0 ? LIBMAIL_GPG_ENCAPSULATE:0,
                             &gi);

       free(argvec);
       fclose(out_fp);
       close(out_dup);
       fclose(in_fp);
       close(in_dup);
       free(k);
       if (passfd)
              fclose(passfd);

       return i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gpgencryptkeys ( const char *  )

Definition at line 282 of file gpg.c.

{
       listpubsec(0, encrypt_key_default, select_keys);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gpgexportkey ( const char *  ,
int  ,
int(*)(const char *, size_t, void *)  ,
void *   
)

Definition at line 735 of file gpg.c.

{
       gpginiterr();

       return (libmail_gpg_exportkey(GPGDIR, issecret, fingerprint,
                                  func,
                                  gpg_error,
                                  arg));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gpglistpub ( )

Definition at line 147 of file gpg.c.

{
       printf("<table width=\"100%%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" class=\"gpgpubkeys\">");
       listpubsec(0, show_key, NULL);
       printf("</table>");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gpglistsec ( )

Definition at line 154 of file gpg.c.

{
       printf("<table width=\"100%%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" class=\"gpgseckeys\">");
       listpubsec(1, show_key, NULL);
       printf("</table>");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gpgselectkey ( )

Definition at line 188 of file gpg.c.

{
       char *default_key=pref_getdefaultgpgkey();

       listpubsec(1, select_key_default, default_key);

       if (default_key)
              free(default_key);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gpgselectprivkey ( )

Definition at line 203 of file gpg.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void gpgselectpubkey ( )

Definition at line 198 of file gpg.c.

Here is the call graph for this function:

Here is the caller graph for this function: