annotate src/c-client/auth_log.c @ 4:d741b3ecc917 draft

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

yatex.org