1 /* ========================================================================
2 * Copyright 2020 Eduardo Chappa
3 * Copyright 1988-2006 University of Washington
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
16 * Program: EXTERNAL authenticator
18 * Author: Mark Crispin
19 * Networks and Distributed Computing
20 * Computing & Communications
21 * University of Washington
22 * Administration Building, AG-44
24 * Internet: MRC@CAC.Washington.EDU
27 * Last Edited: 30 August 2006
30 long auth_external_client (authchallenge_t challenger
,authrespond_t responder
,
31 char *service
,NETMBX
*mb
,void *stream
, unsigned long port
,
32 unsigned long *trial
,char *user
);
33 char *auth_external_server (authresponse_t responder
,int argc
,char *argv
[]);
35 AUTHENTICATOR auth_ext
= { /* secure, has full auth, hidden */
36 AU_SECURE
| AU_AUTHUSER
| AU_HIDE
,
37 "EXTERNAL", /* authenticator name */
38 NIL
, /* always valid */
39 auth_external_client
, /* client method */
40 auth_external_server
, /* server method */
41 NIL
/* next authenticator */
44 /* Client authenticator
45 * Accepts: challenger function
48 * parsed network mailbox structure
49 * stream argument for functions
50 * pointer to current trial count
52 * Returns: T if success, NIL otherwise, number of trials incremented if retry
55 long auth_external_client (authchallenge_t challenger
,authrespond_t responder
,
56 char *service
,NETMBX
*mb
,void *stream
, unsigned long port
,
57 unsigned long *trial
,char *user
)
62 *trial
= 65535; /* never retry */
63 if ((challenge
= (*challenger
) (stream
,&clen
)) != NULL
) {
64 fs_give ((void **) &challenge
);
65 /* send authorization id (empty string OK) */
66 if ((*responder
) (stream
,strcpy (user
,mb
->user
),strlen (mb
->user
))) {
67 if ((challenge
= (*challenger
) (stream
,&clen
)) != NULL
)
68 fs_give ((void **) &challenge
);
69 else ret
= LONGT
; /* check the authentication */
76 /* Server authenticator
77 * Accepts: responder function
80 * Returns: authenticated user name or NIL
83 char *auth_external_server (authresponse_t responder
,int argc
,char *argv
[])
87 char *authenid
= (char *) mail_parameters (NIL
,GET_EXTERNALAUTHID
,NIL
);
89 /* get authorization identity */
90 if (authenid
&& (authid
= (*responder
) ("",0,&len
))) {
91 /* note: responders null-terminate */
92 if (*authid
? authserver_login (authid
,authenid
,argc
,argv
) :
93 authserver_login (authenid
,NIL
,argc
,argv
)) ret
= myusername ();
94 fs_give ((void **) &authid
);