1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 /* Copyright (C) 2002-2004 Novell, Inc.
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.
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.
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.
20 /* Global Catalog test program */
32 #include "e2k-global-catalog.h"
34 #include "test-utils.h"
40 do_lookup (E2kGlobalCatalog *gc, const char *user)
42 E2kGlobalCatalogStatus status;
43 E2kGlobalCatalogEntry *entry;
44 E2kGlobalCatalogLookupType type;
50 type = E2K_GLOBAL_CATALOG_LOOKUP_BY_LEGACY_EXCHANGE_DN;
51 else if (strchr (user, '@'))
52 type = E2K_GLOBAL_CATALOG_LOOKUP_BY_EMAIL;
54 type = E2K_GLOBAL_CATALOG_LOOKUP_BY_DN;
56 flags = E2K_GLOBAL_CATALOG_LOOKUP_SID |
57 E2K_GLOBAL_CATALOG_LOOKUP_EMAIL |
58 E2K_GLOBAL_CATALOG_LOOKUP_MAILBOX |
59 E2K_GLOBAL_CATALOG_LOOKUP_LEGACY_EXCHANGE_DN |
60 E2K_GLOBAL_CATALOG_LOOKUP_DELEGATES |
61 E2K_GLOBAL_CATALOG_LOOKUP_DELEGATORS |
62 E2K_GLOBAL_CATALOG_LOOKUP_QUOTA |
63 E2K_GLOBAL_CATALOG_LOOKUP_ACCOUNT_CONTROL;
65 e2k_operation_init (&op);
66 status = e2k_global_catalog_lookup (gc, &op, type, user, flags, &entry);
67 // e2k_operation_free (&op);
70 case E2K_GLOBAL_CATALOG_OK:
72 case E2K_GLOBAL_CATALOG_NO_SUCH_USER:
73 printf ("No entry for %s\n", user);
76 case E2K_GLOBAL_CATALOG_NO_DATA:
77 printf ("Entry for %s contains no data\n", user);
80 case E2K_GLOBAL_CATALOG_AUTH_FAILED:
81 printf ("Authentication failed (try DOMAIN\\username)\n");
85 printf ("Error looking up user\n");
90 printf ("%s (%s)\n", entry->display_name, entry->dn);
92 printf (" email: %s\n", entry->email);
94 printf (" mailbox: %s on %s\n", entry->mailbox, entry->exchange_server);
95 if (entry->legacy_exchange_dn)
96 printf (" Exchange 5.5 DN: %s\n", entry->legacy_exchange_dn);
98 printf (" sid: %s\n", e2k_sid_get_string_sid (entry->sid));
99 if (entry->delegates) {
100 printf (" delegates:\n");
101 for (i = 0; i < entry->delegates->len; i++)
102 printf (" %s\n", (char *)entry->delegates->pdata[i]);
104 if (entry->delegators) {
105 printf (" delegators:\n");
106 for (i = 0; i < entry->delegators->len; i++)
107 printf (" %s\n", (char *)entry->delegators->pdata[i]);
110 if (entry->quota_warn || entry->quota_nosend || entry->quota_norecv )
111 printf (" Mail Quota Info:\n");
112 if (entry->quota_warn)
113 printf (" Issue Quota warning at : %d\n", entry->quota_warn);
114 if (entry->quota_nosend)
115 printf (" Stop sending mails at : %d\n", entry->quota_nosend);
116 if (entry->quota_norecv)
117 printf (" Stop sending and recieving mails at : %d\n", entry->quota_norecv);
118 if (entry->user_account_control)
119 printf (" user_account_control : %d\n", entry->user_account_control);
122 maxAge = lookup_passwd_max_age (gc, &op);
123 printf("Password max age is %f \n", maxAge);
124 pwd_exp_days = (maxAge * 0.000000100)/86400 ;
125 printf("Password expiery period is %d \n", pwd_exp_days);
127 e2k_operation_free (&op);
129 e2k_global_catalog_entry_free (gc, entry);
134 lookup_dn (E2kGlobalCatalog *gc, const char *id)
136 E2kGlobalCatalogEntry *entry;
137 E2kGlobalCatalogLookupType type;
138 E2kGlobalCatalogStatus status;
142 type = E2K_GLOBAL_CATALOG_LOOKUP_BY_LEGACY_EXCHANGE_DN;
143 else if (strchr (id, '@'))
144 type = E2K_GLOBAL_CATALOG_LOOKUP_BY_EMAIL;
146 return g_strdup (id);
148 e2k_operation_init (&op);
149 status = e2k_global_catalog_lookup (gc, &op, type, id, 0, &entry);
150 e2k_operation_free (&op);
153 case E2K_GLOBAL_CATALOG_OK:
155 case E2K_GLOBAL_CATALOG_NO_SUCH_USER:
156 printf ("No entry for %s\n", id);
160 printf ("Error looking up user %s\n", id);
165 dn = g_strdup (entry->dn);
166 e2k_global_catalog_entry_free (gc, entry);
172 do_modify (E2kGlobalCatalog *gc, const char *user,
173 int deleg_op, const char *delegate)
175 char *self_dn, *deleg_dn;
176 E2kGlobalCatalogStatus status;
178 self_dn = lookup_dn (gc, user);
179 deleg_dn = lookup_dn (gc, delegate);
181 e2k_operation_init (&op);
183 status = e2k_global_catalog_add_delegate (gc, &op, self_dn, deleg_dn);
185 status = e2k_global_catalog_remove_delegate (gc, &op, self_dn, deleg_dn);
186 e2k_operation_free (&op);
189 case E2K_GLOBAL_CATALOG_OK:
192 case E2K_GLOBAL_CATALOG_BAD_DATA:
193 printf ("Invalid delegate DN\n");
195 case E2K_GLOBAL_CATALOG_NO_DATA:
196 printf ("No such delegate to remove\n");
198 case E2K_GLOBAL_CATALOG_EXISTS:
199 printf ("That user is already a delegate\n");
212 e2k_operation_cancel (&op);
219 static pthread_t cancel_thread;
221 if (!cancel_thread) {
222 pthread_create (&cancel_thread, NULL, cancel, NULL);
227 const char *test_program_name = "gctest";
230 test_main (int argc, char **argv)
234 if (argc < 3 || argc > 4 ||
235 (argc == 4 && argv[3][0] != '+' && argv[3][0] != '-')) {
236 fprintf (stderr, "Usage: %s server email-or-dn [[+|-]delegate]\n", argv[0]);
240 signal (SIGINT, quit);
243 gc = test_get_gc (server);
246 do_lookup (gc, argv[2]);
248 do_modify (gc, argv[2], argv[3][0], argv[3] + 1);