imapext-2007

view src/c-client/auth_ext.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
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: EXTERNAL 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: 6 April 2005
26 * Last Edited: 30 August 2006
27 */
29 long auth_external_client (authchallenge_t challenger,authrespond_t responder,
30 char *service,NETMBX *mb,void *stream,
31 unsigned long *trial,char *user);
32 char *auth_external_server (authresponse_t responder,int argc,char *argv[]);
34 AUTHENTICATOR auth_ext = { /* secure, has full auth, hidden */
35 AU_SECURE | AU_AUTHUSER | AU_HIDE,
36 "EXTERNAL", /* authenticator name */
37 NIL, /* always valid */
38 auth_external_client, /* client method */
39 auth_external_server, /* server method */
40 NIL /* next authenticator */
41 };
43 /* Client authenticator
44 * Accepts: challenger function
45 * responder function
46 * SASL service name
47 * parsed network mailbox structure
48 * stream argument for functions
49 * pointer to current trial count
50 * returned user name
51 * Returns: T if success, NIL otherwise, number of trials incremented if retry
52 */
54 long auth_external_client (authchallenge_t challenger,authrespond_t responder,
55 char *service,NETMBX *mb,void *stream,
56 unsigned long *trial,char *user)
57 {
58 void *challenge;
59 unsigned long clen;
60 long ret = NIL;
61 *trial = 65535; /* never retry */
62 if (challenge = (*challenger) (stream,&clen)) {
63 fs_give ((void **) &challenge);
64 /* send authorization id (empty string OK) */
65 if ((*responder) (stream,strcpy (user,mb->user),strlen (mb->user))) {
66 if (challenge = (*challenger) (stream,&clen))
67 fs_give ((void **) &challenge);
68 else ret = LONGT; /* check the authentication */
69 }
70 }
71 return ret;
72 }
75 /* Server authenticator
76 * Accepts: responder function
77 * argument count
78 * argument vector
79 * Returns: authenticated user name or NIL
80 */
82 char *auth_external_server (authresponse_t responder,int argc,char *argv[])
83 {
84 unsigned long len;
85 char *authid;
86 char *authenid = (char *) mail_parameters (NIL,GET_EXTERNALAUTHID,NIL);
87 char *ret = NIL;
88 /* get authorization identity */
89 if (authenid && (authid = (*responder) ("",0,&len))) {
90 /* note: responders null-terminate */
91 if (*authid ? authserver_login (authid,authenid,argc,argv) :
92 authserver_login (authenid,NIL,argc,argv)) ret = myusername ();
93 fs_give ((void **) &authid);
94 }
95 return ret;
96 }

UW-IMAP'd extensions by yuuji