// Enable or disable the secure mode, default is enabled void CSecureEditEx::EnableSecureMode(BOOL bEnable) { if(m_bSecMode == bEnable) return; // Nothing to do LPTSTR lpSource = GetPassword(); ASSERT(lpSource != NULL); ASSERT((int)_tcslen(lpSource) == m_nOldLen); const int iPos = static_cast<int>(GetSel() & 0xFFFF); _DeleteAll(); m_bSecMode = bEnable; if(lpSource != NULL) { m_nOldLen = (int)_tcslen(lpSource); if(bEnable == FALSE) SetWindowText(lpSource); else { if(m_nOldLen != 0) { _InsertCharacters(0, lpSource, (unsigned int)m_nOldLen); _tcsset_s(lpSource, m_nOldLen + 1, TCH_STDPWCHAR); } SetWindowText(lpSource); } if((iPos >= 0) && (iPos <= m_nOldLen)) SetSel(iPos, iPos, FALSE); else { ASSERT(FALSE); } } DeletePassword(lpSource); lpSource = NULL; }
int main( int argc, char *argv[] ) { enum { UNSET, SHOW_HELP, CHECK_VERSION, INSTALL, UNINSTALL } mode = UNSET; PCSTR pSmbdPath = NULL; PSTR pFoundSmbdPath = NULL; DWORD error = 0; DWORD argIndex = 0; LW_RTL_LOG_LEVEL logLevel = LW_RTL_LOG_LEVEL_ERROR; PCSTR pErrorSymbol = NULL; PSTR pVersion = NULL; BOOLEAN smbdExists = FALSE; BOOLEAN force = FALSE; for (argIndex = 1; argIndex < argc; argIndex++) { if (!strcmp(argv[argIndex], "--check-version")) { if (mode == UNSET) { mode = CHECK_VERSION; } else { mode = SHOW_HELP; } } else if (!strcmp(argv[argIndex], "--install")) { if (mode == UNSET) { mode = INSTALL; } else { mode = SHOW_HELP; } } else if (!strcmp(argv[argIndex], "--uninstall")) { if (mode == UNSET) { mode = UNINSTALL; } else { mode = SHOW_HELP; } } else if (!strcmp(argv[argIndex], "--force")) { if (mode == INSTALL || mode== UNINSTALL) { force = TRUE; } else { mode = SHOW_HELP; } } else if (!strcmp(argv[argIndex], "--loglevel")) { argIndex++; if (argIndex >= argc) { error = ERROR_INVALID_PARAMETER; BAIL_ON_LSA_ERROR(error); } if (!strcmp(argv[argIndex], "error")) { logLevel = LW_RTL_LOG_LEVEL_ERROR; } else if (!strcmp(argv[argIndex], "warning")) { logLevel = LW_RTL_LOG_LEVEL_WARNING; } else if (!strcmp(argv[argIndex], "info")) { logLevel = LW_RTL_LOG_LEVEL_INFO; } else if (!strcmp(argv[argIndex], "verbose")) { logLevel = LW_RTL_LOG_LEVEL_VERBOSE; } else if (!strcmp(argv[argIndex], "debug")) { logLevel = LW_RTL_LOG_LEVEL_DEBUG; } else { error = ERROR_INVALID_PARAMETER; BAIL_ON_LSA_ERROR(error); } } else if (argIndex == argc - 1) { pSmbdPath = argv[argIndex]; } else { mode = SHOW_HELP; } } if (mode == UNSET || mode == SHOW_HELP) { ShowUsage(argv[0]); goto cleanup; } LwRtlLogSetCallback(LogCallback, NULL); LwRtlLogSetLevel(logLevel); if (pSmbdPath == NULL) { PCSTR pSearchPath = "/usr/sbin:/usr/local/sbin:/usr/local/samba/sbin:/opt/csw/samba/sbin:/opt/sfw/samba/sbin:/opt/csw/bin:/usr/local/bin"; error = FindFileInPath( "smbd", pSearchPath, &pFoundSmbdPath); if (error == ERROR_FILE_NOT_FOUND) { LW_RTL_LOG_ERROR("The smbd file could not be automatically found on your system. The search path was '%s'. Pass the correct location as the last argument to this program.", pSearchPath); } BAIL_ON_LSA_ERROR(error); pSmbdPath = pFoundSmbdPath; } error = LwCheckFileTypeExists( pSmbdPath, LWFILE_REGULAR, &smbdExists); BAIL_ON_LSA_ERROR(error); if (!smbdExists) { error = LwCheckFileTypeExists( pSmbdPath, LWFILE_SYMLINK, &smbdExists); BAIL_ON_LSA_ERROR(error); } if (!smbdExists) { LW_RTL_LOG_ERROR("Smbd file not found at path '%s'", pSmbdPath); } error = CheckSambaVersion(pSmbdPath, &pVersion); if (force == FALSE) { BAIL_ON_LSA_ERROR(error); } if (mode == CHECK_VERSION) { fprintf(stderr, "Samba version supported\n"); } else if (mode == INSTALL) { if (geteuid() != 0) { fprintf(stderr, "Please use the root account to install the Samba interop libraries\n"); goto cleanup; } error = InstallWbclient(pSmbdPath); BAIL_ON_LSA_ERROR(error); if (pVersion && strncmp(pVersion, "3.0.", sizeof("3.0.") - 1) == 0) { // Only Samba 3.0.x needs this error = InstallLwiCompat(pSmbdPath); BAIL_ON_LSA_ERROR(error); } error = SynchronizePassword( pSmbdPath); BAIL_ON_LSA_ERROR(error); fprintf(stderr, "Install successful\n"); } else if (mode == UNINSTALL) { if (geteuid() != 0) { fprintf(stderr, "Please use the root account to uninstall the Samba interop libraries\n"); goto cleanup; } error = UninstallWbclient(pSmbdPath); BAIL_ON_LSA_ERROR(error); error = UninstallLwiCompat(pSmbdPath); BAIL_ON_LSA_ERROR(error); error = DeletePassword( pSmbdPath); BAIL_ON_LSA_ERROR(error); fprintf(stderr, "Uninstall successful\n"); } else { fprintf(stderr, "Uninstall mode not implemented\n"); error = ERROR_INVALID_PARAMETER; BAIL_ON_LSA_ERROR(error); } cleanup: LW_SAFE_FREE_STRING(pFoundSmbdPath); LW_SAFE_FREE_STRING(pVersion); if (error) { pErrorSymbol = LwWin32ErrorToName(error); if (pErrorSymbol != NULL) { fprintf(stderr, "Error: %s\n", pErrorSymbol); } else { fprintf(stderr, "Unknown error\n"); } } return error; }
int main( int argc, char *argv[] ) { enum { UNSET, SHOW_HELP, CHECK_VERSION, INSTALL, UNINSTALL } mode = UNSET; PCSTR pSmbdPath = NULL; PSTR pFoundSmbdPath = NULL; DWORD error = 0; DWORD argIndex = 0; LW_RTL_LOG_LEVEL logLevel = LW_RTL_LOG_LEVEL_ERROR; PCSTR pErrorSymbol = NULL; for (argIndex = 1; argIndex < argc; argIndex++) { if (!strcmp(argv[argIndex], "--check-version")) { if (mode == UNSET) { mode = CHECK_VERSION; } else { mode = SHOW_HELP; } } else if (!strcmp(argv[argIndex], "--install")) { if (mode == UNSET) { mode = INSTALL; } else { mode = SHOW_HELP; } } else if (!strcmp(argv[argIndex], "--uninstall")) { if (mode == UNSET) { mode = UNINSTALL; } else { mode = SHOW_HELP; } } else if (!strcmp(argv[argIndex], "--loglevel")) { argIndex++; if (argIndex >= argc) { error = ERROR_INVALID_PARAMETER; BAIL_ON_LSA_ERROR(error); } if (!strcmp(argv[argIndex], "error")) { logLevel = LW_RTL_LOG_LEVEL_ERROR; } else if (!strcmp(argv[argIndex], "warning")) { logLevel = LW_RTL_LOG_LEVEL_WARNING; } else if (!strcmp(argv[argIndex], "info")) { logLevel = LW_RTL_LOG_LEVEL_INFO; } else if (!strcmp(argv[argIndex], "verbose")) { logLevel = LW_RTL_LOG_LEVEL_VERBOSE; } else if (!strcmp(argv[argIndex], "debug")) { logLevel = LW_RTL_LOG_LEVEL_DEBUG; } else { error = ERROR_INVALID_PARAMETER; BAIL_ON_LSA_ERROR(error); } } else if (argIndex == argc - 1) { pSmbdPath = argv[2]; } else { mode = SHOW_HELP; } } if (mode == UNSET || mode == SHOW_HELP) { ShowUsage(argv[0]); goto cleanup; } LwRtlLogSetCallback(LogCallback, NULL); LwRtlLogSetLevel(logLevel); if (pSmbdPath == NULL) { error = FindFileInPath( "smbd", "/usr/sbin", &pFoundSmbdPath); BAIL_ON_LSA_ERROR(error); pSmbdPath = pFoundSmbdPath; } error = CheckSambaVersion(pSmbdPath); BAIL_ON_LSA_ERROR(error); if (mode == CHECK_VERSION) { fprintf(stderr, "Samba version supported\n"); } else if (mode == INSTALL) { error = InstallWbclient(pSmbdPath); BAIL_ON_LSA_ERROR(error); error = InstallLwiCompat(pSmbdPath); BAIL_ON_LSA_ERROR(error); error = SynchronizePassword( pSmbdPath); BAIL_ON_LSA_ERROR(error); fprintf(stderr, "Install successful\n"); } else if (mode == UNINSTALL) { error = UninstallWbclient(pSmbdPath); BAIL_ON_LSA_ERROR(error); error = UninstallLwiCompat(pSmbdPath); BAIL_ON_LSA_ERROR(error); error = DeletePassword( pSmbdPath); BAIL_ON_LSA_ERROR(error); fprintf(stderr, "Uninstall successful\n"); } else { fprintf(stderr, "Uninstall mode not implemented\n"); error = ERROR_INVALID_PARAMETER; BAIL_ON_LSA_ERROR(error); } cleanup: LW_SAFE_FREE_STRING(pFoundSmbdPath); if (error) { pErrorSymbol = LwWin32ErrorToName(error); if (pErrorSymbol != NULL) { fprintf(stderr, "Error: %s\n", pErrorSymbol); } else { fprintf(stderr, "Unknown error\n"); } } return error; }