Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / servers / exchange / lib / actest.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Copyright (C) 2003, 2004 Novell, Inc.
4  *
5  * This  program is free  software; you  can redistribute  it and/or
6  * modify it under the terms of version 2  of the GNU General Public
7  * License as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /* Autoconfig test program */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <pthread.h>
27 #include <signal.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #include "e2k-autoconfig.h"
32 #include "test-utils.h"
33
34 const char *test_program_name = "actest";
35
36 static E2kOperation op;
37
38 static void *
39 cancel (void *data)
40 {
41         e2k_operation_cancel (&op);
42         return NULL;
43 }
44
45 static void
46 quit (int sig)
47 {
48         static pthread_t cancel_thread;
49
50         if (!cancel_thread) {
51                 pthread_create (&cancel_thread, NULL, cancel, NULL);
52         } else
53                 exit (0);
54 }
55
56 void
57 test_main (int argc, char **argv)
58 {
59         E2kAutoconfig *ac;
60         E2kAutoconfigResult result;
61         const char *username, *password, *owa_uri, *gc_server;
62
63         signal (SIGINT, quit);
64
65         if (argc < 2 || argc > 4) {
66                 fprintf (stderr, "Usage: %s username [OWA URL] [Global Catalog server]\n", argv[0]);
67                 exit (1);
68         }
69
70         username = argv[1];
71         password = test_get_password (username, NULL);
72
73         owa_uri = argc > 2 ? argv[2] : NULL;
74         gc_server = argc > 3 ? argv[3] : NULL;
75
76         e2k_operation_init (&op);
77         ac = e2k_autoconfig_new (owa_uri, username, password,
78                                  E2K_AUTOCONFIG_USE_EITHER);
79
80         if (ac->owa_uri) {
81                 if (!owa_uri)
82                         printf ("[Default OWA URI: %s]\n", ac->owa_uri);
83         } else {
84                 printf ("No default OWA URI available. Must specify on commandline.\n");
85                 goto done;
86         }
87
88         if (ac->gc_server)
89                 printf ("[Default GC: %s]\n", ac->gc_server);
90         if (ac->nt_domain)
91                 printf ("[Default NT Domain: %s]\n", ac->nt_domain);
92         if (ac->w2k_domain)
93                 printf ("[Default W2k Domain: %s]\n", ac->w2k_domain);
94         printf ("\n");
95
96         if (gc_server)
97                 e2k_autoconfig_set_gc_server (ac, gc_server, -1);
98
99         result = e2k_autoconfig_check_exchange (ac, &op);
100         if (result != E2K_AUTOCONFIG_OK) {
101                 const char *msg;
102                 switch (result) {
103                 case E2K_AUTOCONFIG_CANT_RESOLVE:
104                         msg = "Could not resolve hostname";
105                         break;
106                 case E2K_AUTOCONFIG_CANT_CONNECT:
107                         msg = "Could not connect to server";
108                         break;
109                 case E2K_AUTOCONFIG_REDIRECT:
110                         msg = "Multiple redirection";
111                         break;
112                 case E2K_AUTOCONFIG_AUTH_ERROR:
113                         msg = "Authentication error. Password incorrect?";
114                         break;
115                 case E2K_AUTOCONFIG_AUTH_ERROR_TRY_DOMAIN:
116                         msg = "Authentication error. Password incorrect, or try DOMAIN\\username?";
117                         break;
118                 case E2K_AUTOCONFIG_AUTH_ERROR_TRY_BASIC:
119                         msg = "Authentication error. Password incorrect, or try Basic auth?";
120                         break;
121                 case E2K_AUTOCONFIG_AUTH_ERROR_TRY_NTLM:
122                         msg = "Authentication error. Password incorrect, or try NTLM auth?";
123                         break;
124                 case E2K_AUTOCONFIG_TRY_SSL:
125                         msg = "Need to use SSL";
126                         break;
127                 case E2K_AUTOCONFIG_EXCHANGE_5_5:
128                         msg = "This is an Exchange 5.5 server";
129                         break;
130                 case E2K_AUTOCONFIG_NOT_EXCHANGE:
131                         msg = "Server does not appear to be Exchange";
132                         break;
133                 case E2K_AUTOCONFIG_NO_OWA:
134                         msg = "Did not find OWA at given URL";
135                         break;
136                 case E2K_AUTOCONFIG_NO_MAILBOX:
137                         msg = "You don't seem to have a mailbox here";
138                         break;
139                 case E2K_AUTOCONFIG_CANT_BPROPFIND:
140                         msg = "Server does not allow BPROPFIND";
141                         break;
142                 case E2K_AUTOCONFIG_CANCELLED:
143                         msg = "Cancelled";
144                         break;
145                 case E2K_AUTOCONFIG_FAILED:
146                 default:
147                         msg = "Unknown error";
148                         break;
149                 }
150
151                 printf ("Exchange check to %s failed:\n  %s\n",
152                         ac->owa_uri, msg);
153                 goto done;
154         }
155
156         result = e2k_autoconfig_check_global_catalog (ac, &op);
157         if (result != E2K_AUTOCONFIG_OK) {
158                 const char *msg;
159                 switch (result) {
160                 case E2K_AUTOCONFIG_CANT_RESOLVE:
161                         msg = "Could not resolve GC server";
162                         break;
163                 case E2K_AUTOCONFIG_NO_MAILBOX:
164                         msg = "No data for user";
165                         break;
166                 case E2K_AUTOCONFIG_AUTH_ERROR_TRY_DOMAIN:
167                         msg = "Authentication error. Try DOMAIN\\username?";
168                         break;
169                 case E2K_AUTOCONFIG_CANCELLED:
170                         msg = "Cancelled";
171                         break;
172                 case E2K_AUTOCONFIG_FAILED:
173                 default:
174                         msg = "Unknown error";
175                         break;
176                 }
177
178                 printf ("\nGlobal Catalog check failed: %s\n", msg);
179                 if (!ac->gc_server) {
180                         if (ac->w2k_domain)
181                                 printf ("got domain=%s but ", ac->w2k_domain);
182                         printf ("could not autodetect.\nSpecify GC on command-line.\n");
183                 }
184                 goto done;
185         }
186
187         printf ("%s is an Exchange Server %s\n\n", ac->exchange_server,
188                 ac->version == E2K_EXCHANGE_2000 ? "2000" :
189                 ac->version == E2K_EXCHANGE_2003 ? "2003" :
190                 "[Unknown version]");
191
192         printf ("Name: %s\nEmail: %s\nTimezone: %s\nAccount URL: %s\n\n",
193                 ac->display_name, ac->email, ac->timezone, ac->account_uri);
194
195         if (!ac->pf_server)
196                 printf ("Warning: public folder server was defaulted\n\n");
197  done:
198         e2k_operation_free (&op);
199         e2k_autoconfig_free (ac);
200         test_quit ();
201 }