Back to index

courier  0.68.2
Functions
auth.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int prelogin (const char *)
const char * do_login (const char *, const char *, const char *)
const char * login_returnaddr ()
const char * login_fromhdr ()
int login_changepwd (const char *, const char *, const char *, int *)
int changepw (const char *service, const char *uid, const char *opwd, const char *npwd)

Function Documentation

int changepw ( const char *  service,
const char *  uid,
const char *  opwd,
const char *  npwd 
)

Definition at line 42 of file changepw.c.

{
       pid_t p, p2;
       int waitstat;
       int pipefd[2];
       FILE *fp;

       if (badstr(uid) || badstr(opwd) || badstr(npwd))
       {
              errno=EINVAL;
              return -1;
       }

       signal(SIGCHLD, SIG_DFL);
       signal(SIGPIPE, SIG_IGN);

        if (pipe(pipefd) < 0)
        {
                perror("CRIT: authdaemon: pipe() failed");
                errno=EINVAL;
                return (-1);
        }

        p=fork();

        if (p == 0)
        {
                char *argv[2];

              argv[0]=SQWEBPASSWD;
              argv[1]=0;
              dup2(pipefd[0], 0);
              close(pipefd[0]);
              close(pipefd[1]);
              execv(argv[0], argv);
                perror("CRIT: failed to execute " SQWEBPASSWD);
              exit(1);
       }

       close(pipefd[0]);

       if ((fp=fdopen(pipefd[1], "w")) != 0)
       {
              fprintf(fp, "%s\t%s\t%s\t%s\n",
                     service, uid, opwd, npwd);
              fclose(fp);
       }
       close(pipefd[1]);

        while ((p2=wait(&waitstat)) != p)
        {
                if (p2 < 0 && errno == ECHILD)
                {
                        perror("CRIT: authdaemon: wait() failed");
                        errno=EPERM;
                        return (-1);
                }
        }

        if (WIFEXITED(waitstat) && WEXITSTATUS(waitstat) == 0)
                return (0);

       errno=EPERM;
       return (-1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* do_login ( const char *  ,
const char *  ,
const char *   
)

Definition at line 170 of file auth.c.

{
       if (auth_login("webmail", u, p, doauthlogin, (void *)u))
       {
              courier_safe_printf("INFO: LOGIN FAILED, user=%s, ip=[%s]",
                              u?u:"", ip);
              return NULL;
       }

       fprintf(stderr, "INFO: LOGIN, user=%s, ip=[%s]\n", u, ip);
       return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int login_changepwd ( const char *  ,
const char *  ,
const char *  ,
int *   
)

Definition at line 202 of file auth.c.

{
       if (nochangepass())
              return -1;

       *rc= -1;

       if (changepw("webmail", u, oldpwd, newpwd) == 0)
       {
              *rc=0;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* login_fromhdr ( )

Definition at line 243 of file auth.c.

{
const char *address=login_returnaddr();
const char *fullname=getenv("AUTHFULLNAME");
int    l;
const char *p;
char   *q;

static char *hdrbuf=0;

FILE *fp;
char authcharset[128];
char *ufullname=0;
static char *uhdrbuf=0;

       if (!fullname || !*fullname)
              return (address);    /* That was easy */

       authcharset[0] = 0;
       if ((fp=fopen(AUTHCHARSET, "r")))
       {
              char *p;
              if (fgets(authcharset, sizeof(authcharset), fp) == NULL)
                     authcharset[0]=0;
              fclose(fp);

              if ((p=strchr(authcharset, '\n')))
                     *p = '\0';
       }

       if (authcharset[0] == 0
           && sqwebmail_system_charset && *sqwebmail_system_charset
           && strcasecmp(sqwebmail_system_charset, "ASCII"))
              strncat(authcharset, sqwebmail_system_charset,
                     sizeof(authcharset)-1);

       if (authcharset[0]
           && sqwebmail_content_charset && *sqwebmail_content_charset
           && (ufullname=libmail_u_convert_toutf8(fullname, authcharset,NULL)))
              fullname = ufullname;

       l=sizeof("\"\" <>")+strlen(address)+strlen(fullname);

       for (p=fullname; *p; p++)
              if (*p == '"' || *p == '\\' || *p == '(' || *p == ')' ||
                     *p == '<' || *p == '>')     ++l;

       for (p=address; *p; p++)
              if (*p == '"' || *p == '\\' || *p == '(' || *p == ')' ||
                     *p == '<' || *p == '>')     ++l;

       if (hdrbuf)   free(hdrbuf);
       hdrbuf=malloc(l);
       if (!hdrbuf)  enomem();
       q=hdrbuf;
       *q++='"';
       for (p=fullname; *p; p++)
       {
              if (*p == '"' || *p == '\\' || *p == '(' || *p == ')' ||
                     *p == '<' || *p == '>')     *q++ = '\\';
              *q++= *p;
       }
       *q++='"';
       *q++=' ';
       *q++='<';
       for (p=address; *p; p++)
       {
              if (*p == '"' || *p == '\\' || *p == '(' || *p == ')' ||
                     *p == '<' || *p == '>')     *q++ = '\\';
              *q++= *p;
       }
       *q++='>';
       *q=0;

       if (ufullname)       free(ufullname);
       if (uhdrbuf)  free(uhdrbuf);
       if ((uhdrbuf=libmail_u_convert_fromutf8(hdrbuf,
                                          sqwebmail_content_charset,
                                          NULL)) != NULL)
              return (uhdrbuf);

       return (hdrbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* login_returnaddr ( )

Definition at line 222 of file auth.c.

{
       static char *addrbuf=0;
       const char *p, *domain="";
       
       if ((p=getenv("AUTHENTICATED")) == NULL || *p == 0)
              p=getenv("AUTHADDR");
       if (!p)       p="";
       if (strchr(p, '@') == 0)
              domain=myhostname();

       if (addrbuf)  free(addrbuf);
       addrbuf=malloc(strlen(domain)+strlen(p)+2);
       if (!addrbuf) enomem();

       strcpy(addrbuf, p);
       if (*domain)
              strcat(strcat(addrbuf, "@"), domain);
       return (addrbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int prelogin ( const char *  )

Definition at line 217 of file auth.c.

{
       return auth_getuserinfo("webmail", u, doauthlogin, (void *)u);
}

Here is the call graph for this function:

Here is the caller graph for this function: