imapext-2007

view src/c-client/auth_log.c @ 1:28a55bc1110c

[mq]: imapext
author yuuji@gentei.org
date Mon, 14 Sep 2009 19:23:11 +0900
parents ada5e610ab86
children 2366b362676d
line source
1 /* ========================================================================
2 * Copyright 1988-2006 University of Washington
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *
11 * ========================================================================
12 */
14 /*
15 * Program: Login authenticator
16 *
17 * Author: Mark Crispin
18 * Networks and Distributed Computing
19 * Computing & Communications
20 * University of Washington
21 * Administration Building, AG-44
22 * Seattle, WA 98195
23 * Internet: MRC@CAC.Washington.EDU
24 *
25 * Date: 5 December 1995
26 * Last Edited: 30 August 2006
27 */
29 long auth_login_client (authchallenge_t challenger,authrespond_t responder,
30 char *service,NETMBX *mb,void *stream,
31 unsigned long *trial,char *user);
32 char *auth_login_server (authresponse_t responder,int argc,char *argv[]);
34 AUTHENTICATOR auth_log = {
35 AU_HIDE, /* hidden */
36 "LOGIN", /* authenticator name */
37 NIL, /* always valid */
38 auth_login_client, /* client method */
39 auth_login_server, /* server method */
40 NIL /* next authenticator */
41 };
43 #define PWD_USER "User Name"
44 #define PWD_PWD "Password"
46 /* Client authenticator
47 * Accepts: challenger function
48 * responder function
49 * SASL service name
50 * parsed network mailbox structure
51 * stream argument for functions
52 * pointer to current trial count
53 * returned user name
54 * Returns: T if success, NIL otherwise, number of trials incremented if retry
55 */
57 long auth_login_client (authchallenge_t challenger,authrespond_t responder,
58 char *service,NETMBX *mb,void *stream,
59 unsigned long *trial,char *user)
60 {
61 char pwd[MAILTMPLEN];
62 void *challenge;
63 unsigned long clen;
64 long ret = NIL;
65 /* get user name prompt */
66 if (challenge = (*challenger) (stream,&clen)) {
67 fs_give ((void **) &challenge);
68 pwd[0] = NIL; /* prompt user */
69 mm_login (mb,user,pwd,*trial);
70 if (!pwd[0]) { /* user requested abort */
71 (*responder) (stream,NIL,0);
72 *trial = 0; /* cancel subsequent attempts */
73 ret = LONGT; /* will get a BAD response back */
74 }
75 /* send user name */
76 else if ((*responder) (stream,user,strlen (user)) &&
77 (challenge = (*challenger) (stream,&clen))) {
78 fs_give ((void **) &challenge);
79 /* send password */
80 if ((*responder) (stream,pwd,strlen (pwd))) {
81 if (challenge = (*challenger) (stream,&clen))
82 fs_give ((void **) &challenge);
83 else {
84 ++*trial; /* can try again if necessary */
85 ret = LONGT; /* check the authentication */
86 }
87 }
88 }
89 }
90 memset (pwd,0,MAILTMPLEN); /* erase password */
91 if (!ret) *trial = 65535; /* don't retry if bad protocol */
92 return ret;
93 }
96 /* Server authenticator
97 * Accepts: responder function
98 * argument count
99 * argument vector
100 * Returns: authenticated user name or NIL
101 */
103 char *auth_login_server (authresponse_t responder,int argc,char *argv[])
104 {
105 char *ret = NIL;
106 char *user,*pass,*authuser;
107 if (user = (*responder) (PWD_USER,sizeof (PWD_USER),NIL)) {
108 #ifdef QMAIL
109 extern char* conv_virtualdomain(char*);
110 user = conv_virtualdomain(user);
111 #endif
112 if (pass = (*responder) (PWD_PWD,sizeof (PWD_PWD),NIL)) {
113 /* delimit user from possible admin */
114 if (authuser = strchr (user,'*')) *authuser++ = '\0';
115 if (server_login (user,pass,authuser,argc,argv)) ret = myusername ();
116 fs_give ((void **) &pass);
117 }
118 fs_give ((void **) &user);
119 }
120 return ret;
121 }

UW-IMAP'd extensions by yuuji