114
115
fprintf(stderr, "CTRL-C caught ... Deleting profile\n");
115
116
if ((retval = DeleteProfile(g_mapi_ctx, g_profname)) != MAPI_E_SUCCESS) {
116
mapi_errstr("DeleteProfile", GetLastError());
117
mapi_errstr("DeleteProfile", retval);
119
120
(void) signal(SIGINT, SIG_DFL);
123
static bool mapiprofile_create(const char *profdb, const char *profname,
124
static bool mapiprofile_create(struct mapi_context *mapi_ctx,
125
const char *profdb, const char *profname,
124
126
const char *pattern, const char *username,
125
127
const char *password, const char *address,
126
128
const char *language, const char *workstation,
144
mem_ctx = talloc_named(NULL, 0, "mapiprofile_create");
146
retval = MAPIInitialize(&mapi_ctx, profdb);
147
if (retval != MAPI_E_SUCCESS) {
148
mapi_errstr("MAPIInitialize", GetLastError());
149
talloc_free(mem_ctx);
145
mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_create");
153
147
/* catch CTRL-C */
154
148
g_profname = profname;
173
167
retval = OpenProfile(mapi_ctx, &profile, profname, NULL);
174
168
if (retval == MAPI_E_SUCCESS) {
175
169
fprintf(stderr, "[ERROR] mapiprofile: profile \"%s\" already exists\n", profname);
176
MAPIUninitialize(mapi_ctx);
177
170
talloc_free(mem_ctx);
181
174
retval = CreateProfile(mapi_ctx, profname, username, password, flags);
182
175
if (retval != MAPI_E_SUCCESS) {
183
mapi_errstr("CreateProfile", GetLastError());
176
mapi_errstr("CreateProfile", retval);
184
177
talloc_free(mem_ctx);
209
202
printf("Invalid Language supplied or unknown system language '%s\n'", language);
210
203
printf("Deleting profile\n");
211
204
if ((retval = DeleteProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
212
mapi_errstr("DeleteProfile", GetLastError());
205
mapi_errstr("DeleteProfile", retval);
214
207
talloc_free(mem_ctx);
232
225
retval = MapiLogonProvider(mapi_ctx, &session, profname, password, PROVIDER_ID_NSPI);
233
226
if (retval != MAPI_E_SUCCESS) {
234
mapi_errstr("MapiLogonProvider", GetLastError());
227
mapi_errstr("MapiLogonProvider", retval);
235
228
printf("Deleting profile\n");
236
229
if ((retval = DeleteProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
237
mapi_errstr("DeleteProfile", GetLastError());
230
mapi_errstr("DeleteProfile", retval);
239
232
talloc_free(mem_ctx);
247
240
retval = ProcessNetworkProfile(session, username, (mapi_profile_callback_t) callback, "Select a user id");
248
241
if (retval != MAPI_E_SUCCESS && retval != 0x1) {
249
mapi_errstr("ProcessNetworkProfile", GetLastError());
242
mapi_errstr("ProcessNetworkProfile", retval);
250
243
printf("Deleting profile\n");
251
244
if ((retval = DeleteProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
252
mapi_errstr("DeleteProfile", GetLastError());
245
mapi_errstr("DeleteProfile", retval);
254
247
talloc_free(mem_ctx);
260
253
talloc_free(mem_ctx);
262
MAPIUninitialize(mapi_ctx);
267
static void mapiprofile_delete(const char *profdb, const char *profname)
258
static void mapiprofile_delete(struct mapi_context *mapi_ctx, const char *profdb, const char *profname)
269
260
enum MAPISTATUS retval;
270
struct mapi_context *mapi_ctx;
272
if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
273
mapi_errstr("MAPIInitialize", GetLastError());
277
262
if ((retval = DeleteProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
278
mapi_errstr("DeleteProfile", GetLastError());
263
mapi_errstr("DeleteProfile", retval);
282
267
printf("Profile %s deleted from database %s\n", profname, profdb);
284
MAPIUninitialize(mapi_ctx);
288
static void mapiprofile_rename(const char *profdb, const char *old_profname, const char *new_profname)
271
static void mapiprofile_rename(struct mapi_context *mapi_ctx, const char *profdb, const char *old_profname, const char *new_profname)
290
273
TALLOC_CTX *mem_ctx;
291
274
enum MAPISTATUS retval;
292
struct mapi_context *mapi_ctx;
295
if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
296
mapi_errstr("MAPIInitialize", retval);
300
mem_ctx = talloc_named(NULL, 0, "mapiprofile_rename");
277
mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_rename");
302
279
if (!old_profname) {
303
280
if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
319
296
talloc_free(profname);
320
297
talloc_free(mem_ctx);
321
MAPIUninitialize(mapi_ctx);
325
static void mapiprofile_set_default(const char *profdb, const char *profname)
301
static void mapiprofile_set_default(struct mapi_context *mapi_ctx, const char *profdb, const char *profname)
327
303
enum MAPISTATUS retval;
328
struct mapi_context *mapi_ctx;
330
if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
331
mapi_errstr("MAPIInitialize", GetLastError());
335
305
if ((retval = SetDefaultProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
336
mapi_errstr("SetDefaultProfile", GetLastError());
306
mapi_errstr("SetDefaultProfile", retval);
340
310
printf("Profile %s is now set the default one\n", profname);
342
MAPIUninitialize(mapi_ctx);
345
static void mapiprofile_get_default(const char *profdb)
313
static void mapiprofile_get_default(struct mapi_context *mapi_ctx, const char *profdb)
347
315
enum MAPISTATUS retval;
348
struct mapi_context *mapi_ctx;
351
if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
352
mapi_errstr("MAPIInitialize", GetLastError());
356
318
if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
357
mapi_errstr("GetDefaultProfile", GetLastError());
319
mapi_errstr("GetDefaultProfile", retval);
361
323
printf("Default profile is set to %s\n", profname);
363
325
talloc_free(profname);
364
MAPIUninitialize(mapi_ctx);
367
static void mapiprofile_get_fqdn(const char *profdb,
368
const char *opt_profname,
328
static void mapiprofile_get_fqdn(struct mapi_context *mapi_ctx,
330
const char *opt_profname,
369
331
const char *password,
370
332
bool opt_dumpdata)
372
334
TALLOC_CTX *mem_ctx;
373
335
enum MAPISTATUS retval;
374
struct mapi_context *mapi_ctx;
375
336
struct mapi_session *session = NULL;
376
337
const char *serverFQDN;
379
if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
380
mapi_errstr("MAPIInitialize", GetLastError());
384
340
SetMAPIDumpData(mapi_ctx, opt_dumpdata);
386
mem_ctx = talloc_named(NULL, 0, "mapiprofile_get_fqdn");
342
mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_get_fqdn");
388
344
if (!opt_profname) {
389
345
if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
390
mapi_errstr("GetDefaultProfile", GetLastError());
346
mapi_errstr("GetDefaultProfile", retval);
391
347
talloc_free(mem_ctx);
399
355
talloc_free(profname);
400
356
talloc_free(mem_ctx);
401
357
if (retval != MAPI_E_SUCCESS) {
402
mapi_errstr("MapiLogonProvider", GetLastError());
358
mapi_errstr("MapiLogonProvider", retval);
406
362
retval = RfrGetFQDNFromLegacyDN(mapi_ctx, session, &serverFQDN);
407
363
if (retval != MAPI_E_SUCCESS) {
408
mapi_errstr("RfrGetFQDNFromLegacyDN", GetLastError());
364
mapi_errstr("RfrGetFQDNFromLegacyDN", retval);
412
368
printf("%s is at %s\n", mapi_ctx->session->profile->homemdb, serverFQDN);
414
MAPIUninitialize(mapi_ctx);
417
static void mapiprofile_list(const char *profdb)
371
static void mapiprofile_list(struct mapi_context *mapi_ctx, const char *profdb)
419
373
enum MAPISTATUS retval;
420
struct mapi_context *mapi_ctx;
421
374
struct SRowSet proftable;
422
375
uint32_t count = 0;
424
if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
425
mapi_errstr("MAPIInitialize", GetLastError());
429
377
memset(&proftable, 0, sizeof (struct SRowSet));
430
378
if ((retval = GetProfileTable(mapi_ctx, &proftable)) != MAPI_E_SUCCESS) {
431
mapi_errstr("GetProfileTable", GetLastError());
379
mapi_errstr("GetProfileTable", retval);
452
MAPIUninitialize(mapi_ctx);
455
static void mapiprofile_dump(const char *profdb, const char *opt_profname)
401
static void mapiprofile_dump(struct mapi_context *mapi_ctx, const char *profdb, const char *opt_profname)
457
403
TALLOC_CTX *mem_ctx;
458
404
enum MAPISTATUS retval;
459
struct mapi_context *mapi_ctx;
460
405
struct mapi_profile profile;
462
407
char *exchange_version = NULL;
464
if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
465
mapi_errstr("MAPIInitialize", GetLastError());
469
mem_ctx = talloc_named(NULL, 0, "mapiprofile_dump");
409
mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_dump");
471
411
if (!opt_profname) {
472
412
if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
473
mapi_errstr("GetDefaultProfile", GetLastError());
413
mapi_errstr("GetDefaultProfile", retval);
474
414
talloc_free(mem_ctx);
516
456
talloc_free(mem_ctx);
517
MAPIUninitialize(mapi_ctx);
520
static void mapiprofile_attribute(const char *profdb, const char *opt_profname,
459
static void mapiprofile_attribute(struct mapi_context *mapi_ctx, const char *profdb, const char *opt_profname,
521
460
const char *attribute)
523
462
TALLOC_CTX *mem_ctx;
524
463
enum MAPISTATUS retval;
525
struct mapi_context *mapi_ctx;
526
464
struct mapi_profile profile;
527
465
char *profname = NULL;
528
466
char **value = NULL;
529
467
unsigned int count = 0;
532
if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
533
mapi_errstr("MAPIInitialize", GetLastError());
537
mem_ctx = talloc_named(NULL, 0, "mapiprofile_attribute");
470
mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_attribute");
539
472
if (!opt_profname) {
540
473
if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
541
mapi_errstr("GetDefaultProfile", GetLastError());
474
mapi_errstr("GetDefaultProfile", retval);
548
481
retval = OpenProfile(mapi_ctx, &profile, profname, NULL);
549
482
if (retval && (retval != MAPI_E_INVALID_PARAMETER)) {
550
mapi_errstr("OpenProfile", GetLastError());
483
mapi_errstr("OpenProfile", retval);
551
484
talloc_free(profname);
552
485
talloc_free(mem_ctx);
556
489
if ((retval = GetProfileAttr(&profile, attribute, &count, &value))) {
557
mapi_errstr("ProfileGetAttr", GetLastError());
490
mapi_errstr("ProfileGetAttr", retval);
558
491
talloc_free(profname);
559
492
talloc_free(mem_ctx);
852
789
talloc_free((void *)version);
854
if (! mapiprofile_create(profdb, profname, pattern, username, password, address,
791
if (! mapiprofile_create(mapi_ctx, profdb, profname, pattern, username, password, address,
855
792
language, workstation, domain, realm, nopass, opt_seal,
856
793
opt_dumpdata, opt_debuglevel,
857
794
exchange_version[i].version,
865
mapiprofile_rename(profdb, profname, rename);
802
mapiprofile_rename(mapi_ctx, profdb, profname, rename);
868
805
if (getfqdn == true) {
869
mapiprofile_get_fqdn(profdb, profname, password, opt_dumpdata);
806
mapiprofile_get_fqdn(mapi_ctx, profdb, profname, password, opt_dumpdata);
872
809
if (listlangs == true) {
876
813
if (setdflt == true) {
877
mapiprofile_set_default(profdb, profname);
814
mapiprofile_set_default(mapi_ctx, profdb, profname);
880
817
if (getdflt == true) {
881
mapiprofile_get_default(profdb);
818
mapiprofile_get_default(mapi_ctx, profdb);
884
821
if (delete == true) {
885
mapiprofile_delete(profdb, profname);
822
mapiprofile_delete(mapi_ctx, profdb, profname);
888
825
if (list == true) {
889
mapiprofile_list(profdb);
826
mapiprofile_list(mapi_ctx, profdb);
892
829
if (dump == true) {
893
mapiprofile_dump(profdb, profname);
830
mapiprofile_dump(mapi_ctx, profdb, profname);
897
mapiprofile_attribute(profdb, profname, attribute);
834
mapiprofile_attribute(mapi_ctx, profdb, profname, attribute);