~ubuntu-branches/ubuntu/oneiric/likewise-open/oneiric

« back to all changes in this revision

Viewing changes to domainjoin/domainjoin-cli/src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Salley
  • Date: 2010-11-22 12:06:00 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20101122120600-8lba1fpceot71wlb
Tags: 6.0.0.53010-1
Likewise Open 6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "djdistroinfo.h"
33
33
#include "djsshconf.h"
34
34
#include "djpamconf.h"
35
 
#include "djtimemgmt.h"
36
35
#include "djcli.h"
37
36
#include "djfirewall.h"
38
37
#include "djauditing.h"
39
38
#include "ctprocutils.h"
40
39
#include "lwexc.h"
41
40
 
42
 
#define GCE(x) GOTO_CLEANUP_ON_CENTERROR((x))
 
41
#define GCE(x) GOTO_CLEANUP_ON_DWORD((x))
43
42
 
44
 
CENTERROR ParseUInt(PCSTR in, unsigned int *out)
 
43
DWORD ParseUInt(PCSTR in, unsigned int *out)
45
44
{
46
 
    CENTERROR ceError = CENTERROR_SUCCESS;
 
45
    DWORD ceError = ERROR_SUCCESS;
47
46
    PSTR endPtr;
48
47
    *out = strtoul(in, &endPtr, 10);
49
48
    if(*endPtr != '\0')
50
49
    {
51
 
        GCE(ceError = CENTERROR_INVALID_OPTION_VALUE);
 
50
        GCE(ceError = ERROR_INVALID_PARAMETER);
52
51
    }
53
52
 
54
53
cleanup:
63
62
    fprintf(stdout, "  where options are:\n\n");
64
63
    fprintf(stdout, "    --help                                     Display this help information.\n");
65
64
    fprintf(stdout, "    --help-internal                            Display help for debug commands\n");
66
 
    fprintf(stdout, "    --log {.|path}                             Log to a file (or \".\" to log\n"
 
65
    fprintf(stdout, "    --logfile {.|path}                         Log to a file (or \".\" to log\n"
67
66
                    "                                               to console).\n");
68
67
    fprintf(stdout, "    --loglevel {error|warning|info|verbose}    Adjusts how much logging is\n"
69
68
                    "                                               produced by domainjoin.\n");
76
75
    fprintf(stdout, "    setname <computer name>\n");
77
76
    fprintf(stdout, "    join [--notimesync] [--enable <module> --disable <module> ...] [--ou <organizationalUnit>] <domain name> <user name> [<password>]\n");
78
77
    fprintf(stdout, "    join [--advanced] --preview [--ou <organizationalUnit>] <domain name>\n");
 
78
    fprintf(stdout, "    join [--assumeDefaultDomain] [--userDomainPrefix <short domain name>] [--ou <organizationalUnit>] <domain name>\n");
79
79
    fprintf(stdout, "    join [--ou <organizationalUnit>] --details <module> <domain name>\n");
80
80
    fprintf(stdout, "    leave [--enable <module> --disable <module> ...] [user name] [password]\n");
81
81
    fprintf(stdout, "    leave [--advanced] --preview [user name] [password]\n");
104
104
    fprintf(stdout, "    get_arch\n");
105
105
    fprintf(stdout, "    get_distro\n");
106
106
    fprintf(stdout, "    get_distro_version\n");
107
 
    fprintf(stdout, "    sync_time <domain controller> <allowed drift>\n");
108
107
    fprintf(stdout, "    raise_error <error code | error name | 0xhex error code>\n");
109
108
    fprintf(stdout, "\n");
110
109
}
111
110
 
112
111
static
113
 
CENTERROR
 
112
DWORD
114
113
FillMissingPassword(
115
114
    PCSTR username,
116
115
    PSTR* ppszPassword
117
116
    )
118
117
{
119
 
    CENTERROR ceError = CENTERROR_SUCCESS;
 
118
    DWORD ceError = ERROR_SUCCESS;
120
119
    PSTR pszPassword = NULL;
121
120
    PCSTR pszEnvPassword = NULL;
122
121
 
174
173
{
175
174
    PSTR      wrapped = NULL;
176
175
    int columns;
177
 
    if(!CENTERROR_IS_OK(CTGetTerminalWidth(fileno(stdout), &columns)))
 
176
    if(CTGetTerminalWidth(fileno(stdout), &columns))
178
177
        columns = -1;
179
178
 
180
 
    //This function doesn't return a CENTERROR, so we have to recover as much
 
179
    //This function doesn't return a DWORD, so we have to recover as much
181
180
    //as possible.
182
 
    if(CENTERROR_IS_OK(CTWordWrap(message, &wrapped, 4, columns)))
 
181
    if(!CTWordWrap(message, &wrapped, 4, columns))
183
182
        fprintf(stdout, "Warning: %s\n%s\n\n", title, wrapped);
184
183
    else
185
184
        fprintf(stdout, "Warning: %s\n%s\n\n", title, message);
331
330
        }
332
331
        else if(argc < 2)
333
332
        {
334
 
            LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
333
            LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
335
334
            goto cleanup;
336
335
        }
337
336
        else if(!strcmp(argv[0], "--enable"))
354
353
        }
355
354
        else if(!strcmp(argv[0], "--ou"))
356
355
        {
 
356
            DJ_LOG_INFO("Domainjoin invoked with option --ou %s", argv[1]);
357
357
            CT_SAFE_FREE_STRING(options.ouName);
358
358
            LW_CLEANUP_CTERR(exc, CTStrdup(argv[1], &options.ouName));
359
359
            argv++;
360
360
            argc--;
361
361
        }
 
362
        else if(!strcmp(argv[0], "--assumeDefaultDomain"))
 
363
        {
 
364
            DJ_LOG_INFO("Domainjoin invoked with option --assumeDefaultDomain");
 
365
            options.assumeDefaultDomain = TRUE;
 
366
        }
 
367
        else if(!strcmp(argv[0], "--userDomainPrefix"))
 
368
        {
 
369
            DJ_LOG_INFO("Domainjoin invoked with option --userDomainPrefix %s", argv[1]);
 
370
            options.assumeDefaultDomain = TRUE;
 
371
            CT_SAFE_FREE_STRING(options.userDomainPrefix);
 
372
            LW_CLEANUP_CTERR(exc, CTStrdup(argv[1], &options.userDomainPrefix));
 
373
            argv++;
 
374
            argc--;
 
375
        }
362
376
        else
363
377
        {
364
 
            LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
378
            LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
365
379
            goto cleanup;
366
380
        }
367
381
        argv++;
378
392
        ;
379
393
    else if(argc != 2)
380
394
    {
381
 
        LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
395
        LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
382
396
        goto cleanup;
383
397
    }
384
398
    options.joiningDomain = TRUE;
408
422
                    &enableModules, i, sizeof(PCSTR));
409
423
        if(CTArrayFindString(&disableModules, module) != -1)
410
424
        {
411
 
            LW_RAISE_EX(exc, CENTERROR_INVALID_OPTION_VALUE, "Module already specified", "The module '%s' is listed as being disabled and enabled", module);
 
425
            LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and enabled", module);
412
426
            goto cleanup;
413
427
        }
414
428
        LW_TRY(exc, DJEnableModule(&options, module, TRUE, &LW_EXC));
420
434
                    &disableModules, i, sizeof(PCSTR));
421
435
        if(CTArrayFindString(&enableModules, module) != -1)
422
436
        {
423
 
            LW_RAISE_EX(exc, CENTERROR_INVALID_OPTION_VALUE, "Module already specified", "The module '%s' is listed as being disabled and enabled", module);
 
437
            LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and enabled", module);
424
438
            goto cleanup;
425
439
        }
426
440
        LW_TRY(exc, DJEnableModule(&options, module, FALSE, &LW_EXC));
433
447
        ModuleState *state = DJGetModuleStateByName(&options, module);
434
448
        if(state == NULL)
435
449
        {
436
 
            LW_RAISE_EX(exc, CENTERROR_INVALID_PARAMETER, "Unable to find module.", "Please check the spelling of '%s'. This module cannot be found", module);
 
450
            LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Unable to find module.", "Please check the spelling of '%s'. This module cannot be found", module);
437
451
            goto cleanup;
438
452
        }
439
453
        PrintModuleState(state);
513
527
            preview = TRUE;
514
528
        else if(argc < 2)
515
529
        {
516
 
            LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
530
            LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
517
531
            goto cleanup;
518
532
        }
519
533
        else if(!strcmp(argv[0], "--enable"))
536
550
        }
537
551
        else
538
552
        {
539
 
            LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
553
            LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
540
554
            goto cleanup;
541
555
        }
542
556
        argv++;
550
564
    }
551
565
    else if(argc > 2)
552
566
    {
553
 
        LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
567
        LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
554
568
        goto cleanup;
555
569
    }
556
570
    options.joiningDomain = FALSE;
578
592
                    &enableModules, i, sizeof(PCSTR));
579
593
        if(CTArrayFindString(&disableModules, module) != -1)
580
594
        {
581
 
            LW_RAISE_EX(exc, CENTERROR_INVALID_OPTION_VALUE, "Module already specified", "The module '%s' is listed as being disabled and enabled", module);
 
595
            LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and enabled", module);
582
596
            goto cleanup;
583
597
        }
584
598
        LW_TRY(exc, DJEnableModule(&options, module, TRUE, &LW_EXC));
590
604
                    &disableModules, i, sizeof(PCSTR));
591
605
        if(CTArrayFindString(&enableModules, module) != -1)
592
606
        {
593
 
            LW_RAISE_EX(exc, CENTERROR_INVALID_OPTION_VALUE, "Module already specified", "The module '%s' is listed as being disabled and enabled", module);
 
607
            LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and enabled", module);
594
608
            goto cleanup;
595
609
        }
596
610
        LW_TRY(exc, DJEnableModule(&options, module, FALSE, &LW_EXC));
603
617
        ModuleState *state = DJGetModuleStateByName(&options, module);
604
618
        if(state == NULL)
605
619
        {
606
 
            LW_RAISE_EX(exc, CENTERROR_INVALID_PARAMETER, "Unable to find module.", "Please check the spelling of '%s'. This module cannot be found", module);
 
620
            LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Unable to find module.", "Please check the spelling of '%s'. This module cannot be found", module);
607
621
            goto cleanup;
608
622
        }
609
623
        PrintModuleState(state);
675
689
            dwEnable = ENABLE_TYPE_DISABLE;
676
690
        else if(argc < 2)
677
691
        {
678
 
            LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
692
            LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
679
693
            goto cleanup;
680
694
        }
681
695
        else if(!strcmp(argv[0], "--testprefix"))
698
712
        }
699
713
        else
700
714
        {
701
 
            LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
715
            LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
702
716
            goto cleanup;
703
717
        }
704
718
        argv++;
707
721
 
708
722
    if(argc < 1)
709
723
    {
710
 
        LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
724
        LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
711
725
        goto cleanup;
712
726
    }
713
727
 
727
741
        LW_CLEANUP_CTERR(exc, DJConfigureReapSyslog(testPrefix, GetEnableBoolean(dwEnable)));
728
742
    else
729
743
    {
730
 
        LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
744
        LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
731
745
        goto cleanup;
732
746
    }
733
747
    fprintf(stdout, "SUCCESS\n");
754
768
    }
755
769
    if(argc > 0)
756
770
    {
757
 
        LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
771
        LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
758
772
        goto cleanup;
759
773
    }
760
774
 
777
791
    }
778
792
    else
779
793
    {
780
 
        LW_RAISE(exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
794
        LW_RAISE(exc, LW_ERROR_SHOW_USAGE);
781
795
        goto cleanup;
782
796
    }
783
797
    fprintf(stdout, "%s\n", str);
805
819
    char **argPos = argv;
806
820
    int i;
807
821
 
808
 
    if(!CENTERROR_IS_OK(CTGetTerminalWidth(fileno(stdout), &columns)))
 
822
    if(CTGetTerminalWidth(fileno(stdout), &columns))
809
823
        columns = -1;
810
824
 
811
825
    /* Skip the program name */
825
839
        //All options after this point take an argument
826
840
        else if(remainingArgs < 2)
827
841
            showHelp = TRUE;
828
 
        else if(!strcmp(argPos[0], "--log"))
 
842
        else if(!strcmp(argPos[0], "--logfile"))
829
843
        {
830
844
            pszLogFilePath = (++argPos)[0];
831
845
            remainingArgs--;
865
879
    else if (!strcasecmp(logLevel, "verbose"))
866
880
        dwLogLevel = LOG_LEVEL_VERBOSE;
867
881
    else {
868
 
        LW_CLEANUP_CTERR(&exc, CENTERROR_DOMAINJOIN_INVALID_LOG_LEVEL);
 
882
        LW_CLEANUP_CTERR(&exc, LW_ERROR_INVALID_LOG_LEVEL);
869
883
    }
870
884
 
871
885
    if (bNoLog) {
874
888
               !strcmp(pszLogFilePath, ".")) {
875
889
        LW_CLEANUP_CTERR(&exc, dj_init_logging_to_console(dwLogLevel));
876
890
    } else {
877
 
        CENTERROR ceError = dj_init_logging_to_file(dwLogLevel, pszLogFilePath);
878
 
        if(ceError == CENTERROR_ACCESS_DENIED)
 
891
        DWORD ceError = dj_init_logging_to_file(dwLogLevel, pszLogFilePath);
 
892
        if(ceError == ERROR_ACCESS_DENIED)
879
893
        {
880
 
            fprintf(stderr, "Warning: insufficient permissions to log to %s. To enable logging, please specify a different filename with --log <file>.\n",
 
894
            fprintf(stderr, "Warning: insufficient permissions to log to %s. To enable logging, please specify a different filename with --logfile <file>.\n",
881
895
                    pszLogFilePath);
882
 
            ceError = CENTERROR_SUCCESS;
 
896
            ceError = ERROR_SUCCESS;
883
897
            LW_CLEANUP_CTERR(&exc, dj_disable_logging());
884
898
        }
885
899
        LW_CLEANUP_CTERR(&exc, ceError);
915
929
        LW_TRY(&exc, DJNetInitialize(bEnableDcerpcd, &LW_EXC));
916
930
        LW_TRY(&exc, DJSetComputerName(argPos[0], NULL, &LW_EXC));
917
931
    }
918
 
#ifndef ENABLE_MINIMAL
919
 
    else if(!strcmp(argPos[0], "sync_time"))
920
 
    {
921
 
        unsigned int allowedDrift;
922
 
        argPos++;
923
 
        if(--remainingArgs != 2)
924
 
        {
925
 
            ShowUsage();
926
 
            goto cleanup;
927
 
        }
928
 
        LW_CLEANUP_CTERR(&exc, ParseUInt(argPos[1], &allowedDrift));
929
 
        LW_CLEANUP_CTERR(&exc, DJSyncTimeToDC(argPos[0], allowedDrift));
930
 
    }
931
 
#endif
932
932
    else if(!strcmp(argPos[0], "join"))
933
933
    {
934
934
        argPos++;
965
965
    {
966
966
        LW_TRY(&exc, DoGetDistroInfo(remainingArgs, argPos, &LW_EXC));
967
967
    }
968
 
    else if(!strcmp(argPos[0], "raise_error"))
969
 
    {
970
 
        CENTERROR ceError;
971
 
        argPos++;
972
 
        if(--remainingArgs != 1)
973
 
        {
974
 
            ShowUsage();
975
 
            goto cleanup;
976
 
        }
977
 
        if (isdigit((int) *argPos[0]))
978
 
            ceError = (CENTERROR) strtoul(argPos[0], NULL, 0);
979
 
        else
980
 
            ceError = (CENTERROR) CTErrorFromName(argPos[0]);
981
 
        LW_CLEANUP_CTERR(&exc, ceError);
982
 
    }
983
968
    else
984
969
    {
985
 
        LW_RAISE(&exc, CENTERROR_DOMAINJOIN_SHOW_USAGE);
 
970
        LW_RAISE(&exc, LW_ERROR_SHOW_USAGE);
986
971
        goto cleanup;
987
972
    }
988
973
 
989
974
cleanup:
990
975
 
991
 
    if (!LW_IS_OK(exc) && exc->code == CENTERROR_DOMAINJOIN_SHOW_USAGE)
 
976
    if (!LW_IS_OK(exc) && exc->code == LW_ERROR_SHOW_USAGE)
992
977
    {
993
978
        ShowUsage();
994
979
        LWHandle(&exc);