Beispiel #1
0
extern const char*  Ncbi_strerror(int errnum)
{
#if (defined(NCBI_OS_MSWIN) && defined(_UNICODE)) || \
        (NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__)
    string tmp;
#  if NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__
    TXChar xbuf[256];
    NcbiSys_strerror_s(xbuf,sizeof(xbuf)/sizeof(TXChar),errnum);
    tmp = _T_STDSTRING(xbuf);
#  else
    tmp = _T_STDSTRING( NcbiSys_strerror(errnum) );
#  endif
    char* ptr = new char[ tmp.size() + 1];
    strcpy(ptr, tmp.c_str());
    s_TlsStrerrorMessage.SetValue(ptr, s_TlsStrerrorMessageCleanup);
    return ptr;
#else
    return NcbiSys_strerror(errnum);
#endif
}
Beispiel #2
0
static bool x_GetAccountNameBySid(PSID sid, string* account, int* domatch = 0)
{
    _ASSERT(account);

    // Use predefined buffers for account/domain names to avoid additional
    // step to get its sizes. According to MSDN max account/domain size
    // do not exceed MAX_ACCOUNT_LEN symbols (char or wchar).

    TXChar   account_name[MAX_ACCOUNT_LEN + 2];
    TXChar   domain_name [MAX_ACCOUNT_LEN + 2];
    DWORD    account_size = sizeof(account_name)/sizeof(account_name[0]) - 1;
    DWORD    domain_size  = sizeof(domain_name)/sizeof(domain_name[0]) - 1;
    SID_NAME_USE use;

    // Always get both account & domain name, even we don't need last.
    // Because if domain name is NULL, this function can throw unhandled
    // exception in Unicode builds on some platforms.
    if ( !LookupAccountSid(NULL, sid, 
                           account_name, &account_size,
                           domain_name,  &domain_size, &use) ) {
        CNcbiError::SetFromWindowsError();
        return false;
    }

    // Save account information
    account_name[account_size] = _TX('\0');
    account->assign(_T_STDSTRING(account_name));

    if (domatch) {
        domain_name[domain_size] = _TX('\0');
        string domain(_T_STDSTRING(domain_name));
        if (*domatch != int(use)  ||  domain.empty()
            ||  NStr::EqualNocase(domain, "builtin")
            ||  NStr::FindNoCase(domain, " ") != NPOS
            /*||  x_DomainIsLocalComputer(domain_name)*/) {
            *domatch = 0;
        }
    }
    return true;
}
Beispiel #3
0
BEGIN_NCBI_SCOPE


string CWinSecurity::GetUserName(void)
{
    TXChar name[UNLEN + 1];
    DWORD  name_size = sizeof(name) / sizeof(name[0]) - 1;

    if ( !::GetUserName(name, &name_size) ) {
        CNcbiError::SetFromWindowsError();
        return kEmptyStr;
    }
    name[name_size] = _TX('\0');
    return _T_STDSTRING(name);
}
Beispiel #4
0
string NCBI_XNCBI_EXPORT g_GetConfigString(const char* section,
                                           const char* variable,
                                           const char* env_var_name,
                                           const char* default_value)
{
    if ( section  &&  *section ) {
        CNcbiApplication* app = CNcbiApplication::Instance();
        if ( app  &&  app->HasLoadedConfig() ) {
            const string& value = app->GetConfig().Get(section, variable);
            if ( !value.empty() ) {
#ifdef _DEBUG
                if ( s_CanDumpConfig() ) {
                    DUMP_CONFIG(15, "NCBI_CONFIG: str variable"
                                    " [" << section << "]"
                                    " " << variable <<
                                    " = \"" << value << "\""
                                    " from registry");
                }
#endif
                return value;
            }
        }
    }
    const TXChar* value = s_GetEnv(section, variable, env_var_name);
    if ( value ) {
#ifdef _DEBUG
        if ( s_CanDumpConfig() ) {
            if ( section  &&  *section ) {
                DUMP_CONFIG(16, "NCBI_CONFIG: str variable"
                                " [" << section << "]"
                                " " << variable <<
                                " = \"" << value << "\""
                                " from env var " <<
                                s_GetEnvVarName(section, variable, env_var_name));
            }
            else {
                DUMP_CONFIG(17, "NCBI_CONFIG: str variable"
                                " " << variable <<
                                " = \"" << value << "\""
                                " from env var");
            }
        }
#endif
        return _T_STDSTRING(value);
    }
    const char* dvalue = default_value? default_value: "";
#ifdef _DEBUG
    if ( s_CanDumpConfig() ) {
        if ( section  &&  *section ) {
            DUMP_CONFIG(18, "NCBI_CONFIG: str variable"
                            " [" << section << "]"
                            " " << variable <<
                            " = \"" << dvalue << "\""
                            " by default");
        }
        else {
            DUMP_CONFIG(19, "NCBI_CONFIG: str variable"
                            " " << variable <<
                            " = \"" << dvalue << "\""
                            " by default");
        }
    }
#endif
    return dvalue;
}