imapext-2007

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/c-client/auth_ext.c	Mon Sep 14 15:17:45 2009 +0900
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* ========================================================================
     1.5 + * Copyright 1988-2006 University of Washington
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *     http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * 
    1.14 + * ========================================================================
    1.15 + */
    1.16 +
    1.17 +/*
    1.18 + * Program:	EXTERNAL authenticator
    1.19 + *
    1.20 + * Author:	Mark Crispin
    1.21 + *		Networks and Distributed Computing
    1.22 + *		Computing & Communications
    1.23 + *		University of Washington
    1.24 + *		Administration Building, AG-44
    1.25 + *		Seattle, WA  98195
    1.26 + *		Internet: MRC@CAC.Washington.EDU
    1.27 + *
    1.28 + * Date:	6 April 2005
    1.29 + * Last Edited:	30 August 2006
    1.30 + */
    1.31 +
    1.32 +long auth_external_client (authchallenge_t challenger,authrespond_t responder,
    1.33 +			  char *service,NETMBX *mb,void *stream,
    1.34 +			  unsigned long *trial,char *user);
    1.35 +char *auth_external_server (authresponse_t responder,int argc,char *argv[]);
    1.36 +
    1.37 +AUTHENTICATOR auth_ext = {	/* secure, has full auth, hidden */
    1.38 +  AU_SECURE | AU_AUTHUSER | AU_HIDE,
    1.39 +  "EXTERNAL",			/* authenticator name */
    1.40 +  NIL,				/* always valid */
    1.41 +  auth_external_client,		/* client method */
    1.42 +  auth_external_server,		/* server method */
    1.43 +  NIL				/* next authenticator */
    1.44 +};
    1.45 +
    1.46 +/* Client authenticator
    1.47 + * Accepts: challenger function
    1.48 + *	   responder function
    1.49 + *	   SASL service name
    1.50 + *	   parsed network mailbox structure
    1.51 + *	   stream argument for functions
    1.52 + *	   pointer to current trial count
    1.53 + *	   returned user name
    1.54 + * Returns: T if success, NIL otherwise, number of trials incremented if retry
    1.55 + */
    1.56 +
    1.57 +long auth_external_client (authchallenge_t challenger,authrespond_t responder,
    1.58 +			  char *service,NETMBX *mb,void *stream,
    1.59 +			  unsigned long *trial,char *user)
    1.60 +{
    1.61 +  void *challenge;
    1.62 +  unsigned long clen;
    1.63 +  long ret = NIL;
    1.64 +  *trial = 65535;		/* never retry */
    1.65 +  if (challenge = (*challenger) (stream,&clen)) {
    1.66 +    fs_give ((void **) &challenge);
    1.67 +				/* send authorization id (empty string OK) */
    1.68 +    if ((*responder) (stream,strcpy (user,mb->user),strlen (mb->user))) {
    1.69 +      if (challenge = (*challenger) (stream,&clen))
    1.70 +	fs_give ((void **) &challenge);
    1.71 +      else ret = LONGT;		/* check the authentication */
    1.72 +    }
    1.73 +  }
    1.74 +  return ret;
    1.75 +}
    1.76 +
    1.77 +
    1.78 +/* Server authenticator
    1.79 + * Accepts: responder function
    1.80 + *	    argument count
    1.81 + *	    argument vector
    1.82 + * Returns: authenticated user name or NIL
    1.83 + */
    1.84 +
    1.85 +char *auth_external_server (authresponse_t responder,int argc,char *argv[])
    1.86 +{
    1.87 +  unsigned long len;
    1.88 +  char *authid;
    1.89 +  char *authenid = (char *) mail_parameters (NIL,GET_EXTERNALAUTHID,NIL);
    1.90 +  char *ret = NIL;
    1.91 +				/* get authorization identity */
    1.92 +  if (authenid && (authid = (*responder) ("",0,&len))) {
    1.93 +				/* note: responders null-terminate */
    1.94 +    if (*authid ? authserver_login (authid,authenid,argc,argv) :
    1.95 +	authserver_login (authenid,NIL,argc,argv)) ret = myusername ();
    1.96 +    fs_give ((void **) &authid);
    1.97 +  }
    1.98 +  return ret;
    1.99 +}

UW-IMAP'd extensions by yuuji