Remove obsolete $Cambridge$ CVS revision strings.
[exim.git] / src / src / auths / check_serv_cond.c
CommitLineData
16ff981e
PH
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
0a49a7a4 5/* Copyright (c) University of Cambridge 1995 - 2009 */
16ff981e
PH
6/* See the file NOTICE for conditions of use and distribution. */
7
8#include "../exim.h"
9
10/* This module contains the function server_condition(), which is used
11by all authenticators. */
12
13
14/*************************************************
15* Check server_condition *
16*************************************************/
17
18/* This function is called from the server code of all authenticators. For
19plaintext, it is always called: the argument cannot be empty, because for
20plaintext, setting server_condition is what enables it as a server
21authenticator. For all the other authenticators, this function is called after
22they have authenticated, to enable additional authorization to be done.
23
24Argument: the authenticator's instance block
25
26Returns:
27 OK NULL argument, or success
28 DEFER couldn't complete the check
29 FAIL authentication failed
30*/
31
32int
33auth_check_serv_cond(auth_instance *ablock)
34{
35uschar *cond;
36
37HDEBUG(D_auth)
38 {
39 int i;
40 debug_printf("%s authenticator:\n", ablock->name);
41 for (i = 0; i < AUTH_VARS; i++)
42 {
43 if (auth_vars[i] != NULL)
44 debug_printf(" $auth%d = %s\n", i + 1, auth_vars[i]);
45 }
46 for (i = 1; i <= expand_nmax; i++)
47 debug_printf(" $%d = %.*s\n", i, expand_nlength[i], expand_nstring[i]);
48 debug_print_string(ablock->server_debug_string); /* customized debug */
49 }
50
51/* For the plaintext authenticator, server_condition is never NULL. For the
52rest, an unset condition lets everything through. */
53
54if (ablock->server_condition == NULL) return OK;
55cond = expand_string(ablock->server_condition);
56
57HDEBUG(D_auth)
58 {
59 if (cond == NULL)
60 debug_printf("expansion failed: %s\n", expand_string_message);
61 else
62 debug_printf("expanded string: %s\n", cond);
63 }
64
65/* A forced expansion failure causes authentication to fail. Other expansion
66failures yield DEFER, which will cause a temporary error code to be returned to
67the AUTH command. The problem is at the server end, so the client should try
68again later. */
69
70if (cond == NULL)
71 {
72 if (expand_string_forcedfail) return FAIL;
73 auth_defer_msg = expand_string_message;
74 return DEFER;
75 }
76
77/* Return FAIL for empty string, "0", "no", and "false"; return OK for
78"1", "yes", and "true"; return DEFER for anything else, with the string
79available as an error text for the user. */
80
81if (*cond == 0 ||
82 Ustrcmp(cond, "0") == 0 ||
83 strcmpic(cond, US"no") == 0 ||
84 strcmpic(cond, US"false") == 0)
85 return FAIL;
86
87if (Ustrcmp(cond, "1") == 0 ||
88 strcmpic(cond, US"yes") == 0 ||
89 strcmpic(cond, US"true") == 0)
90 return OK;
91
92auth_defer_msg = cond;
93auth_defer_user_msg = string_sprintf(": %s", cond);
94return DEFER;
95}
96
97/* End of check_serv_cond.c */