DWORD DJGetOptionValue(const DynamicArray *lines, PCSTR stanza, PCSTR name, PSTR *value) { DWORD ceError = ERROR_SUCCESS; ssize_t i = DJFindLine(lines, stanza, name); PCSTR line; PSTR _value = NULL; *value = NULL; if(i == -1) GCE(ceError = ERROR_NOT_FOUND); line = *(PCSTR *)CTArrayGetItem((DynamicArray*)lines, i, sizeof(PCSTR)); while (*line != '\0' && isspace((int)*line)) line++; line += strlen(name); while (*line != '\0' && isspace((int)*line)) line++; if(*line != '=') { GCE(ceError = ERROR_BAD_FORMAT); } line++; GCE(ceError = CTStrdup(line, &_value)); CTStripWhitespace(_value); /* Remove the quotes around the value, if they exist */ if(CTStrStartsWith(_value, "\"") && CTStrEndsWith(_value, "\"")) { size_t len = strlen(_value); memmove(_value, _value + 1, len - 2 ); _value[len - 2 ] = '\0'; } *value = _value; _value = NULL; cleanup: CT_SAFE_FREE_STRING(_value); return ceError; }
int main( int argc, char* argv[] ) { LWException *exc = NULL; int columns; PSTR pszLogFilePath = NULL; BOOLEAN bNoLog = FALSE; PSTR logLevel = "warning"; DWORD dwLogLevel; BOOLEAN showHelp = FALSE; BOOLEAN showInternalHelp = FALSE; int remainingArgs = argc; char **argPos = argv; int i; BOOLEAN directoryExists = FALSE; if(CTGetTerminalWidth(fileno(stdout), &columns)) columns = -1; /* Skip the program name */ argPos++; remainingArgs--; setlocale(LC_ALL, ""); while(remainingArgs > 0 && CTStrStartsWith(argPos[0], "--")) { if(!strcmp(argPos[0], "--help")) showHelp = TRUE; else if(!strcmp(argPos[0], "--help-internal")) showInternalHelp = TRUE; else if(!strcmp(argPos[0], "--nolog")) bNoLog = TRUE; //All options after this point take an argument else if(remainingArgs < 2) showHelp = TRUE; else if(!strcmp(argPos[0], "--logfile")) { pszLogFilePath = (++argPos)[0]; remainingArgs--; } else if(!strcmp(argPos[0], "--loglevel")) { logLevel = (++argPos)[0]; remainingArgs--; } else break; remainingArgs--; argPos++; } if(remainingArgs < 1) showHelp = TRUE; if (showInternalHelp) { ShowUsageInternal(); goto cleanup; } if (showHelp) { ShowUsage(); goto cleanup; } if (!strcasecmp(logLevel, "error")) { dwLogLevel = LOG_LEVEL_ERROR; LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_ERROR); } else if (!strcasecmp(logLevel, "warning")) { dwLogLevel = LOG_LEVEL_WARNING; LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_WARNING); } else if (!strcasecmp(logLevel, "info")) { dwLogLevel = LOG_LEVEL_INFO; LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_INFO); } else if (!strcasecmp(logLevel, "verbose")) { dwLogLevel = LOG_LEVEL_VERBOSE; LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_VERBOSE); } else if (!strcasecmp(logLevel, "debug")) { dwLogLevel = LOG_LEVEL_VERBOSE; LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_DEBUG); } else { LW_CLEANUP_CTERR(&exc, LW_ERROR_INVALID_LOG_LEVEL); } if (pszLogFilePath == NULL) { // Determine the default log path LW_CLEANUP_CTERR(&exc, CTCheckDirectoryExists("/var/log", &directoryExists)); if (directoryExists) { pszLogFilePath = "/var/log/domainjoin-cli.log"; } else { pszLogFilePath = "/var/adm/domainjoin-cli.log"; } } if (bNoLog) { LW_CLEANUP_CTERR(&exc, dj_disable_logging()); } else if (!strcmp(pszLogFilePath, ".")) { LW_CLEANUP_CTERR(&exc, dj_init_logging_to_console(dwLogLevel)); } else { DWORD ceError = dj_init_logging_to_file(dwLogLevel, pszLogFilePath); if(ceError == ERROR_ACCESS_DENIED) { fprintf(stderr, "Warning: insufficient permissions to log to %s. To enable logging, please specify a different filename with --logfile <file>.\n", pszLogFilePath); ceError = ERROR_SUCCESS; LW_CLEANUP_CTERR(&exc, dj_disable_logging()); } else if (ceError == ERROR_FILE_NOT_FOUND) { fprintf(stderr, "Warning: parent directory of log file %s does not exist. To enable logging, please specify a different filename with --logfile <file>.\n", pszLogFilePath); ceError = ERROR_SUCCESS; LW_CLEANUP_CTERR(&exc, dj_disable_logging()); } LW_CLEANUP_CTERR(&exc, ceError); } LwRtlLogSetCallback(RtlLogCallback, NULL); if (!strcmp(argPos[0], "join") || !strcmp(argPos[0], "leave")) { DJ_LOG_INFO("Domainjoin invoked with the %s command (remaining arguments will be printed later):", argPos[0]); // Only print up to the 'join' part for (i = 0; i <= argPos - argv; i++) { DJ_LOG_INFO(" [%s]", argv[i]); } } else { DJ_LOG_INFO("Domainjoin invoked with %d arg(s):", argc); for (i = 0; i < argc; i++) { DJ_LOG_INFO(" [%s]", argv[i]); } } if(!strcmp(argPos[0], "setname")) { PSTR pDomainSuffix = 0; argPos++; if(--remainingArgs != 1) { ShowUsage(); goto cleanup; } pDomainSuffix = strchr(argPos[0], '.'); if (pDomainSuffix) { *pDomainSuffix = 0; pDomainSuffix++; } else { pDomainSuffix = ""; } LW_TRY(&exc, DJSetComputerName(argPos[0], pDomainSuffix, &LW_EXC)); } else if(!strcmp(argPos[0], "join")) { argPos++; remainingArgs--; LW_TRY(&exc, DoJoin(remainingArgs, argPos, columns, &LW_EXC)); } else if(!strcmp(argPos[0], "leave")) { argPos++; remainingArgs--; LW_TRY(&exc, DoLeaveNew(remainingArgs, argPos, columns, &LW_EXC)); } else if(!strcmp(argPos[0], "query")) { LW_TRY(&exc, DoQuery(&LW_EXC)); } else if(!strcmp(argPos[0], "fixfqdn")) LW_TRY(&exc, DoFixFqdn(&LW_EXC)); #ifndef ENABLE_MINIMAL else if(!strcmp(argPos[0], "configure")) { argPos++; remainingArgs--; LW_TRY(&exc, DoConfigure(remainingArgs, argPos, &LW_EXC)); } #endif else if(!strcmp(argPos[0], "get_os_type") || !strcmp(argPos[0], "get_arch") || !strcmp(argPos[0], "get_distro") || !strcmp(argPos[0], "get_distro_version")) { LW_TRY(&exc, DoGetDistroInfo(remainingArgs, argPos, &LW_EXC)); } else { LW_RAISE(&exc, LW_ERROR_SHOW_USAGE); goto cleanup; } cleanup: if (!LW_IS_OK(exc) && exc->code == LW_ERROR_SHOW_USAGE) { ShowUsage(); LWHandle(&exc); } else if (!LW_IS_OK(exc)) { //Ignoring the return value from this because we can't do anything //if there is an error fprintf(stdout, "\n"); LWPrintException(stdout, exc, FALSE); DJLogException(LOG_LEVEL_ERROR, exc); LWHandle(&exc); dj_close_log(); return 1; } dj_close_log(); return 0; }
void DoConfigure(int argc, char **argv, LWException **exc) { EnableType dwEnable = ENABLE_TYPE_AUTO; PCSTR testPrefix = NULL; PCSTR longDomain = NULL; PCSTR shortDomain = NULL; JoinProcessOptions options = { 0 }; while(argc > 0 && CTStrStartsWith(argv[0], "--")) { if(!strcmp(argv[0], "--autoenable")) dwEnable = ENABLE_TYPE_AUTO; else if(!strcmp(argv[0], "--enable")) dwEnable = ENABLE_TYPE_ENABLE; else if(!strcmp(argv[0], "--disable")) dwEnable = ENABLE_TYPE_DISABLE; else if(argc < 2) { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } else if(!strcmp(argv[0], "--testprefix")) { testPrefix = argv[1]; argv++; argc--; } else if(!strcmp(argv[0], "--long")) { longDomain = argv[1]; argv++; argc--; } else if(!strcmp(argv[0], "--short")) { shortDomain = argv[1]; argv++; argc--; } else { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } argv++; argc--; } if(argc < 1) { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } options.joiningDomain = GetEnableBoolean(dwEnable); options.warningCallback = PrintWarning; if(!strcmp(argv[0], "pam")) LW_TRY(exc, DJNewConfigurePamForADLogin(testPrefix, NULL, PrintWarning, GetEnableBoolean(dwEnable), &LW_EXC)); else if(!strcmp(argv[0], "nsswitch")) { LW_TRY(exc, DoNsswitch(&options, &LW_EXC)); } else if(!strcmp(argv[0], "ssh")) LW_TRY(exc, DJConfigureSshForADLogin(GetEnableBoolean(dwEnable), NULL, &LW_EXC)); else if(!strcmp(argv[0], "krb5")) LW_CLEANUP_CTERR(exc, DJModifyKrb5Conf(testPrefix, GetEnableBoolean(dwEnable), longDomain, shortDomain, NULL, NULL)); else if(!strcmp(argv[0], "eventfwdd")) LW_CLEANUP_CTERR(exc, DJConfigureEventFwd(testPrefix, GetEnableBoolean(dwEnable))); else if(!strcmp(argv[0], "reapsysld")) LW_CLEANUP_CTERR(exc, DJConfigureReapSyslog(testPrefix, GetEnableBoolean(dwEnable))); else { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } fprintf(stdout, "SUCCESS\n"); cleanup: ; }
void DoLeaveNew(int argc, char **argv, int columns, LWException **exc) { JoinProcessOptions options; BOOLEAN advanced = FALSE; BOOLEAN preview = FALSE; DynamicArray enableModules, disableModules, ignoreModules; DynamicArray detailModules; size_t i; PSTR moduleDetails = NULL; PSTR wrapped = NULL; int passwordIndex = -1; DJZeroJoinProcessOptions(&options); memset(&enableModules, 0, sizeof(enableModules)); memset(&disableModules, 0, sizeof(disableModules)); memset(&ignoreModules, 0, sizeof(ignoreModules)); memset(&detailModules, 0, sizeof(detailModules)); while(argc > 0 && CTStrStartsWith(argv[0], "--")) { if(!strcmp(argv[0], "--advanced")) advanced = TRUE; else if(!strcmp(argv[0], "--preview")) preview = TRUE; else if(argc < 2) { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } else if(!strcmp(argv[0], "--enable")) { LW_CLEANUP_CTERR(exc, CTArrayAppend(&enableModules, sizeof(PCSTR *), &argv[1], 1)); argv++; argc--; } else if(!strcmp(argv[0], "--disable")) { if(!strcmp(argv[1], "ssh")){ options.ignoreSsh = TRUE; } else { options.ignoreSsh = FALSE; LW_CLEANUP_CTERR(exc, CTArrayAppend(&disableModules, sizeof(PCSTR *), &argv[1], 1)); } argv++; argc--; } else if(!strcmp(argv[0], "--ignore")) { LW_CLEANUP_CTERR(exc, CTArrayAppend(&ignoreModules, sizeof(PCSTR *), &argv[1], 1)); argv++; argc--; } else if(!strcmp(argv[0], "--details")) { LW_CLEANUP_CTERR(exc, CTArrayAppend(&detailModules, sizeof(PCSTR *), &argv[1], 1)); argv++; argc--; } else if(!strcmp(argv[0], "--multiple")) { options.enableMultipleJoins = TRUE; LW_CLEANUP_CTERR(exc, CTStrdup(argv[1], &options.domainName)); argv++; argc--; } else { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } argv++; argc--; } if(argc == 2) { LW_CLEANUP_CTERR(exc, CTStrdup(argv[1], &options.password)); passwordIndex = 1; } else if(argc > 2) { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } options.joiningDomain = FALSE; DJ_LOG_INFO("Domainjoin invoked with %d arg(s) to the leave command:", argc); for(i = 0; i < argc; i++) { DJ_LOG_INFO(" [%s]", i == passwordIndex ? "<password>" : argv[i]); } if(argc > 0) { LW_CLEANUP_CTERR(exc, CTStrdup(argv[0], &options.username)); } options.warningCallback = PrintWarning; options.showTraces = advanced; LW_CLEANUP_CTERR(exc, DJGetComputerName(&options.computerName)); LW_TRY(exc, DJInitModuleStates(&options, &LW_EXC)); for(i = 0; i < enableModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &enableModules, i, sizeof(PCSTR)); if(CTArrayFindString(&disableModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and enabled", module); goto cleanup; } if(CTArrayFindString(&ignoreModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being ignored and enabled", module); goto cleanup; } LW_TRY(exc, DJSetModuleDisposition(&options, module, EnableModule, &LW_EXC)); } for(i = 0; i < disableModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &disableModules, i, sizeof(PCSTR)); if(CTArrayFindString(&enableModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and enabled", module); goto cleanup; } if(CTArrayFindString(&ignoreModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and ignored", module); goto cleanup; } LW_TRY(exc, DJSetModuleDisposition(&options, module, DisableModule, &LW_EXC)); } for(i = 0; i < ignoreModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &ignoreModules, i, sizeof(PCSTR)); if(CTArrayFindString(&enableModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being ignored and enabled", module); goto cleanup; } if(CTArrayFindString(&disableModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being ignored and disabled", module); goto cleanup; } LW_TRY(exc, DJSetModuleDisposition(&options, module, IgnoreModule, &LW_EXC)); } for(i = 0; i < detailModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &detailModules, i, sizeof(PCSTR)); ModuleState *state = DJGetModuleStateByName(&options, module); if(state == NULL) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Unable to find module.", "Please check the spelling of '%s'. This module cannot be found", module); goto cleanup; } PrintModuleState(state); } if(detailModules.size > 0) { PrintStateKey(); } for(i = 0; i < detailModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &detailModules, i, sizeof(PCSTR)); ModuleState *state = DJGetModuleStateByName(&options, module); CT_SAFE_FREE_STRING(moduleDetails); CT_SAFE_FREE_STRING(wrapped); LW_TRY(exc, moduleDetails = state->module->GetChangeDescription(&options, &LW_EXC)); LW_CLEANUP_CTERR(exc, CTWordWrap(moduleDetails, &wrapped, 4, columns)); fprintf(stdout, "\nDetails for '%s':\n%s\n", state->module->longName, wrapped); } if(detailModules.size > 0) goto cleanup; LW_TRY(exc, PrintJoinHeader(&options, &LW_EXC)); if(preview) { PrintModuleStates(advanced, &options); if(!advanced) LW_TRY(exc, DJCheckRequiredEnabled(&options, &LW_EXC)); goto cleanup; } LW_TRY(exc, DJCheckRequiredEnabled(&options, &LW_EXC)); if (options.username != NULL && IsNullOrEmptyString(options.password)) { CT_SAFE_FREE_STRING(options.password); LW_CLEANUP_CTERR(exc, FillMissingPassword(options.username, &options.password)); } LW_TRY(exc, DJRunJoinProcess(&options, &LW_EXC)); fprintf(stdout, "SUCCESS\n"); cleanup: DJFreeJoinProcessOptions(&options); CTArrayFree(&enableModules); CTArrayFree(&disableModules); CTArrayFree(&ignoreModules); CTArrayFree(&detailModules); CT_SAFE_FREE_STRING(moduleDetails); CT_SAFE_FREE_STRING(wrapped); }
void DoJoin(int argc, char **argv, int columns, LWException **exc) { JoinProcessOptions options; BOOLEAN advanced = FALSE; BOOLEAN preview = FALSE; DynamicArray enableModules, disableModules, ignoreModules; DynamicArray detailModules; size_t i; int passwordIndex = -1; PSTR moduleDetails = NULL; PSTR wrapped = NULL; DJZeroJoinProcessOptions(&options); memset(&enableModules, 0, sizeof(enableModules)); memset(&disableModules, 0, sizeof(disableModules)); memset(&ignoreModules, 0, sizeof(ignoreModules)); memset(&detailModules, 0, sizeof(detailModules)); while(argc > 0 && CTStrStartsWith(argv[0], "--")) { if(!strcmp(argv[0], "--advanced")) advanced = TRUE; else if(!strcmp(argv[0], "--preview")) preview = TRUE; else if(!strcmp(argv[0], "--ignore-firewall-ntp")) { printf("Warning: --ignore-firewall-ntp is deprecated. This behavior is now default.\n"); } else if(!strcmp(argv[0], "--ignore-pam")) options.ignorePam = TRUE; else if(!strcmp(argv[0], "--notimesync")) options.disableTimeSync = TRUE; else if(!strcmp(argv[0], "--multiple")) options.enableMultipleJoins = TRUE; else if(!strcmp(argv[0], "--nohosts")) { PCSTR module = "hostname"; LW_CLEANUP_CTERR(exc, CTArrayAppend(&disableModules, sizeof(PCSTR), &module, 1)); } else if(argc < 2) { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } else if(!strcmp(argv[0], "--enable")) { LW_CLEANUP_CTERR(exc, CTArrayAppend(&enableModules, sizeof(PCSTR), &argv[1], 1)); argv++; argc--; } else if(!strcmp(argv[0], "--disable")) { if(!strcmp(argv[1], "ssh")){ options.ignoreSsh = TRUE; } else { options.ignoreSsh = FALSE; LW_CLEANUP_CTERR(exc, CTArrayAppend(&disableModules, sizeof(PCSTR), &argv[1], 1)); } argv++; argc--; } else if(!strcmp(argv[0], "--ignore")) { LW_CLEANUP_CTERR(exc, CTArrayAppend(&ignoreModules, sizeof(PCSTR), &argv[1], 1)); argv++; argc--; } else if(!strcmp(argv[0], "--details")) { LW_CLEANUP_CTERR(exc, CTArrayAppend(&detailModules, sizeof(PCSTR), &argv[1], 1)); argv++; argc--; } else if(!strcmp(argv[0], "--ou")) { DJ_LOG_INFO("Domainjoin invoked with option --ou %s", argv[1]); CT_SAFE_FREE_STRING(options.ouName); LW_CLEANUP_CTERR(exc, CTStrdup(argv[1], &options.ouName)); argv++; argc--; } else if(!strcmp(argv[0], "--uac-flags")) { DJ_LOG_INFO("Domainjoin invoked with option --uac-flags %s", argv[1]); CT_SAFE_FREE_STRING(options.ouName); options.uacFlags = strtoul(argv[1], NULL, 0); argv++; argc--; } else if(!strcmp(argv[0], "--assumeDefaultDomain")) { DJ_LOG_INFO("Domainjoin invoked with option --assumeDefaultDomain"); options.setAssumeDefaultDomain = TRUE; if (!strcasecmp(argv[1], "yes") || !strcasecmp(argv[1], "true") || !strcasecmp(argv[1], "on")) { options.assumeDefaultDomain = TRUE; } else if (!strcasecmp(argv[1], "no") || !strcasecmp(argv[1], "false") || !strcasecmp(argv[1], "off")) { options.assumeDefaultDomain = FALSE; } else { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } argv++; argc--; } else if(!strcmp(argv[0], "--userDomainPrefix")) { DJ_LOG_INFO("Domainjoin invoked with option --userDomainPrefix %s", argv[1]); options.setAssumeDefaultDomain = TRUE; options.assumeDefaultDomain = TRUE; CT_SAFE_FREE_STRING(options.userDomainPrefix); LW_CLEANUP_CTERR(exc, CTStrdup(argv[1], &options.userDomainPrefix)); CTStrToUpper(options.userDomainPrefix); argv++; argc--; } else { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } argv++; argc--; } if(argc == 3) { LW_CLEANUP_CTERR(exc, CTStrdup(argv[2], &options.password)); passwordIndex = 2; } // The join username is not required in preview or details mode. else if(argc == 1 && (preview || detailModules.size != 0) ) ; else if(argc != 2) { LW_RAISE(exc, LW_ERROR_SHOW_USAGE); goto cleanup; } options.joiningDomain = TRUE; DJ_LOG_INFO("Domainjoin invoked with %d arg(s) to the join command:", argc); for(i = 0; i < argc; i++) { DJ_LOG_INFO(" [%s]", i == passwordIndex ? "<password>" : argv[i]); } LW_CLEANUP_CTERR(exc, CTStrdup( argv[0], &options.domainName)); if(argc > 1) { LW_CLEANUP_CTERR(exc, CTStrdup(argv[1], &options.username)); } options.warningCallback = PrintWarning; options.showTraces = advanced; LW_CLEANUP_CTERR(exc, DJGetComputerName(&options.computerName)); LW_TRY(exc, DJInitModuleStates(&options, &LW_EXC)); for(i = 0; i < enableModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &enableModules, i, sizeof(PCSTR)); if(CTArrayFindString(&disableModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and enabled", module); goto cleanup; } if(CTArrayFindString(&ignoreModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being ignored and enabled", module); goto cleanup; } LW_TRY(exc, DJSetModuleDisposition(&options, module, EnableModule, &LW_EXC)); } for(i = 0; i < disableModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &disableModules, i, sizeof(PCSTR)); if(CTArrayFindString(&enableModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and enabled", module); goto cleanup; } if(CTArrayFindString(&ignoreModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being ignored and enabled", module); goto cleanup; } LW_TRY(exc, DJSetModuleDisposition(&options, module, DisableModule, &LW_EXC)); } for(i = 0; i < ignoreModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &ignoreModules, i, sizeof(PCSTR)); if(CTArrayFindString(&enableModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being enabled and ignored", module); goto cleanup; } if(CTArrayFindString(&disableModules, module) != -1) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Module already specified", "The module '%s' is listed as being disabled and ignored", module); goto cleanup; } LW_TRY(exc, DJSetModuleDisposition(&options, module, IgnoreModule, &LW_EXC)); } for(i = 0; i < detailModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &detailModules, i, sizeof(PCSTR)); ModuleState *state = DJGetModuleStateByName(&options, module); if(state == NULL) { LW_RAISE_EX(exc, ERROR_INVALID_PARAMETER, "Unable to find module.", "Please check the spelling of '%s'. This module cannot be found", module); goto cleanup; } PrintModuleState(state); } if(detailModules.size > 0) { PrintStateKey(); } for(i = 0; i < detailModules.size; i++) { PCSTR module = *(PCSTR *)CTArrayGetItem( &detailModules, i, sizeof(PCSTR)); ModuleState *state = DJGetModuleStateByName(&options, module); CT_SAFE_FREE_STRING(moduleDetails); CT_SAFE_FREE_STRING(wrapped); LW_TRY(exc, moduleDetails = state->module->GetChangeDescription(&options, &LW_EXC)); LW_CLEANUP_CTERR(exc, CTWordWrap(moduleDetails, &wrapped, 4, columns)); fprintf(stdout, "\nDetails for '%s':\n%s\n", state->module->longName, wrapped); } if(detailModules.size > 0) goto cleanup; LW_TRY(exc, PrintJoinHeader(&options, &LW_EXC)); if(preview) { PrintModuleStates(advanced, &options); if(!advanced) LW_TRY(exc, DJCheckRequiredEnabled(&options, &LW_EXC)); goto cleanup; } LW_TRY(exc, DJCheckRequiredEnabled(&options, &LW_EXC)); if (IsNullOrEmptyString(options.password)) { CT_SAFE_FREE_STRING(options.password); LW_CLEANUP_CTERR(exc, FillMissingPassword(options.username, &options.password)); } LW_TRY(exc, DJRunJoinProcess(&options, &LW_EXC)); fprintf(stdout, "SUCCESS\n"); cleanup: DJFreeJoinProcessOptions(&options); CTArrayFree(&enableModules); CTArrayFree(&disableModules); CTArrayFree(&ignoreModules); CTArrayFree(&detailModules); CT_SAFE_FREE_STRING(moduleDetails); CT_SAFE_FREE_STRING(wrapped); }
static QueryResult QueryDSPlugin(const JoinProcessOptions *options, LWException **exc) { BOOLEAN exists = FALSE; QueryResult result = NotConfigured; PSTR value = NULL; PSTR valueStart = NULL; BOOLEAN bLikewisePresent = FALSE; if (options->enableMultipleJoins) { result = NotApplicable; goto cleanup; } LW_CLEANUP_CTERR(exc, CTCheckFileOrLinkExists("/usr/bin/dscl", &exists)); if(!exists) { result = NotApplicable; goto cleanup; } LW_CLEANUP_CTERR(exc, DJIsAppleADPluginInUse(&exists)); if(exists) { result = ApplePluginInUse; goto cleanup; } LW_CLEANUP_CTERR(exc, CTCaptureOutput("/usr/bin/dscl /Search -read / dsAttrTypeStandard:SearchPolicy", &value)); CTStripWhitespace(value); valueStart = value; if(CTStrStartsWith(valueStart, "SearchPolicy:")) valueStart += strlen("SearchPolicy:"); CTStripWhitespace(valueStart); if(CTStrStartsWith(valueStart, "dsAttrTypeStandard:")) valueStart += strlen("dsAttrTypeStandard:"); CTStripWhitespace(valueStart); if(options->joiningDomain) { if(strcmp(valueStart, "CSPSearchPath")) goto cleanup; } else { if(strcmp(valueStart, "NSPSearchPath")) goto cleanup; } CT_SAFE_FREE_STRING(value); LW_CLEANUP_CTERR(exc, CTCaptureOutput("/usr/bin/dscl /Search -read / dsAttrTypeStandard:CSPSearchPath", &value)); CTStripWhitespace(value); valueStart = strstr(value, LWDSPLUGIN_NAME); if (valueStart == NULL) { bLikewisePresent = FALSE; } else { switch (valueStart[strlen(LWDSPLUGIN_NAME)]) { case 0: case '\r': case '\n': bLikewisePresent = TRUE; break; default: bLikewisePresent = FALSE; } } if( (bLikewisePresent != 0) != (options->joiningDomain != 0) ) goto cleanup; CT_SAFE_FREE_STRING(value); result = FullyConfigured; cleanup: CT_SAFE_FREE_STRING(value); return result; }