imapext-2007

annotate 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
rev   line source
yuuji@0 1 /* ========================================================================
yuuji@0 2 * Copyright 1988-2006 University of Washington
yuuji@0 3 *
yuuji@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
yuuji@0 5 * you may not use this file except in compliance with the License.
yuuji@0 6 * You may obtain a copy of the License at
yuuji@0 7 *
yuuji@0 8 * http://www.apache.org/licenses/LICENSE-2.0
yuuji@0 9 *
yuuji@0 10 *
yuuji@0 11 * ========================================================================
yuuji@0 12 */
yuuji@0 13
yuuji@0 14 /*
yuuji@0 15 * Program: EXTERNAL authenticator
yuuji@0 16 *
yuuji@0 17 * Author: Mark Crispin
yuuji@0 18 * Networks and Distributed Computing
yuuji@0 19 * Computing & Communications
yuuji@0 20 * University of Washington
yuuji@0 21 * Administration Building, AG-44
yuuji@0 22 * Seattle, WA 98195
yuuji@0 23 * Internet: MRC@CAC.Washington.EDU
yuuji@0 24 *
yuuji@0 25 * Date: 6 April 2005
yuuji@0 26 * Last Edited: 30 August 2006
yuuji@0 27 */
yuuji@0 28
yuuji@0 29 long auth_external_client (authchallenge_t challenger,authrespond_t responder,
yuuji@0 30 char *service,NETMBX *mb,void *stream,
yuuji@0 31 unsigned long *trial,char *user);
yuuji@0 32 char *auth_external_server (authresponse_t responder,int argc,char *argv[]);
yuuji@0 33
yuuji@0 34 AUTHENTICATOR auth_ext = { /* secure, has full auth, hidden */
yuuji@0 35 AU_SECURE | AU_AUTHUSER | AU_HIDE,
yuuji@0 36 "EXTERNAL", /* authenticator name */
yuuji@0 37 NIL, /* always valid */
yuuji@0 38 auth_external_client, /* client method */
yuuji@0 39 auth_external_server, /* server method */
yuuji@0 40 NIL /* next authenticator */
yuuji@0 41 };
yuuji@0 42
yuuji@0 43 /* Client authenticator
yuuji@0 44 * Accepts: challenger function
yuuji@0 45 * responder function
yuuji@0 46 * SASL service name
yuuji@0 47 * parsed network mailbox structure
yuuji@0 48 * stream argument for functions
yuuji@0 49 * pointer to current trial count
yuuji@0 50 * returned user name
yuuji@0 51 * Returns: T if success, NIL otherwise, number of trials incremented if retry
yuuji@0 52 */
yuuji@0 53
yuuji@0 54 long auth_external_client (authchallenge_t challenger,authrespond_t responder,
yuuji@0 55 char *service,NETMBX *mb,void *stream,
yuuji@0 56 unsigned long *trial,char *user)
yuuji@0 57 {
yuuji@0 58 void *challenge;
yuuji@0 59 unsigned long clen;
yuuji@0 60 long ret = NIL;
yuuji@0 61 *trial = 65535; /* never retry */
yuuji@0 62 if (challenge = (*challenger) (stream,&clen)) {
yuuji@0 63 fs_give ((void **) &challenge);
yuuji@0 64 /* send authorization id (empty string OK) */
yuuji@0 65 if ((*responder) (stream,strcpy (user,mb->user),strlen (mb->user))) {
yuuji@0 66 if (challenge = (*challenger) (stream,&clen))
yuuji@0 67 fs_give ((void **) &challenge);
yuuji@0 68 else ret = LONGT; /* check the authentication */
yuuji@0 69 }
yuuji@0 70 }
yuuji@0 71 return ret;
yuuji@0 72 }
yuuji@0 73
yuuji@0 74
yuuji@0 75 /* Server authenticator
yuuji@0 76 * Accepts: responder function
yuuji@0 77 * argument count
yuuji@0 78 * argument vector
yuuji@0 79 * Returns: authenticated user name or NIL
yuuji@0 80 */
yuuji@0 81
yuuji@0 82 char *auth_external_server (authresponse_t responder,int argc,char *argv[])
yuuji@0 83 {
yuuji@0 84 unsigned long len;
yuuji@0 85 char *authid;
yuuji@0 86 char *authenid = (char *) mail_parameters (NIL,GET_EXTERNALAUTHID,NIL);
yuuji@0 87 char *ret = NIL;
yuuji@0 88 /* get authorization identity */
yuuji@0 89 if (authenid && (authid = (*responder) ("",0,&len))) {
yuuji@0 90 /* note: responders null-terminate */
yuuji@0 91 if (*authid ? authserver_login (authid,authenid,argc,argv) :
yuuji@0 92 authserver_login (authenid,NIL,argc,argv)) ret = myusername ();
yuuji@0 93 fs_give ((void **) &authid);
yuuji@0 94 }
yuuji@0 95 return ret;
yuuji@0 96 }

UW-IMAP'd extensions by yuuji