2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: JRD Access Method
|
2003-09-25 13:49:12 +02:00
|
|
|
* MODULE: isc.cpp
|
2001-05-23 15:26:42 +02:00
|
|
|
* DESCRIPTION: General purpose but non-user routines.
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
2002-07-02 11:49:19 +02:00
|
|
|
*
|
2001-05-23 15:26:42 +02:00
|
|
|
* Solaris x86 changes - Konstantin Kuznetsov, Neil McCalden
|
2002-07-02 11:49:19 +02:00
|
|
|
* 26-Sept-2001 Paul Beach - External File Directory Config. Parameter
|
|
|
|
* 17-Oct-2001 Mike Nordell: CPU affinity
|
|
|
|
* 01-Feb-2002 Paul Reeves: Removed hard-coded registry path
|
2002-10-29 03:45:09 +01:00
|
|
|
*
|
|
|
|
* 2002.10.28 Sean Leyne - Completed removal of obsolete "DGUX" port
|
|
|
|
*
|
2002-10-30 07:40:58 +01:00
|
|
|
* 2002.10.29 Sean Leyne - Removed obsolete "Netware" port
|
|
|
|
*
|
2002-10-31 06:06:02 +01:00
|
|
|
* 2002.10.30 Sean Leyne - Removed support for obsolete "PC_PLATFORM" define
|
2002-10-31 06:33:35 +01:00
|
|
|
* 2002.10.30 Sean Leyne - Code Cleanup, removed obsolete "SUN3_3" port
|
2002-10-31 06:06:02 +01:00
|
|
|
*
|
2001-05-23 15:26:42 +02:00
|
|
|
*/
|
2006-02-23 06:22:08 +01:00
|
|
|
|
2001-07-29 19:42:23 +02:00
|
|
|
#include "firebird.h"
|
2004-04-29 00:36:29 +02:00
|
|
|
#include <stdio.h>
|
2001-05-23 15:26:42 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "../jrd/common.h"
|
|
|
|
|
2003-11-11 13:19:20 +01:00
|
|
|
#include "gen/iberror.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/ibase.h"
|
|
|
|
#include "../jrd/jrd.h"
|
|
|
|
#include "../jrd/scl.h"
|
|
|
|
#include "../jrd/gds_proto.h"
|
|
|
|
#include "../jrd/isc_proto.h"
|
|
|
|
#include "../jrd/jrd_proto.h"
|
|
|
|
|
2008-04-09 17:49:46 +02:00
|
|
|
#include "../common/classes/init.h"
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
#ifdef SOLARIS
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
|
|
|
|
2009-11-23 08:31:21 +01:00
|
|
|
// Win32 specific stuff
|
2002-11-25 17:25:31 +01:00
|
|
|
|
|
|
|
#ifdef WIN_NT
|
|
|
|
|
|
|
|
#include <windows.h>
|
2005-08-23 16:25:48 +02:00
|
|
|
#include <aclapi.h>
|
2007-11-19 21:34:10 +01:00
|
|
|
#include <lmcons.h>
|
2002-11-25 17:25:31 +01:00
|
|
|
|
2008-04-09 17:49:46 +02:00
|
|
|
class SecurityAttributes
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit SecurityAttributes(MemoryPool& pool)
|
2009-03-03 13:26:58 +01:00
|
|
|
: m_pool(pool)
|
2008-04-09 17:49:46 +02:00
|
|
|
{
|
|
|
|
// Ensure that our process has the SYNCHRONIZE privilege granted to everyone
|
2008-04-12 13:57:46 +02:00
|
|
|
PSECURITY_DESCRIPTOR pOldSD = NULL;
|
2008-04-09 17:49:46 +02:00
|
|
|
PACL pOldACL = NULL;
|
2009-08-30 21:00:46 +02:00
|
|
|
|
|
|
|
// Pseudo-handles do not work on WinNT. Need real process handle.
|
|
|
|
HANDLE hCurrentProcess = OpenProcess(READ_CONTROL | WRITE_DAC, FALSE, GetCurrentProcessId());
|
|
|
|
if (hCurrentProcess == NULL) {
|
|
|
|
Firebird::system_call_failed::raise("OpenProcess");
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD result = GetSecurityInfo(hCurrentProcess, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION,
|
|
|
|
NULL, NULL, &pOldACL, NULL, &pOldSD);
|
|
|
|
|
2009-11-23 08:31:21 +01:00
|
|
|
if (result == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
2009-08-30 21:00:46 +02:00
|
|
|
// For Win9X - sumulate that the call worked alright
|
|
|
|
pOldACL = NULL;
|
|
|
|
result = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
CloseHandle(hCurrentProcess);
|
|
|
|
Firebird::system_call_failed::raise("GetSecurityInfo", result);
|
|
|
|
}
|
2002-11-25 17:25:31 +01:00
|
|
|
|
2008-04-11 03:38:50 +02:00
|
|
|
// NULL pOldACL means all privileges. If we assign pNewACL in this case
|
2008-04-09 17:49:46 +02:00
|
|
|
// we'll lost all privileges except assigned SYNCHRONIZE
|
2008-12-02 08:09:49 +01:00
|
|
|
if (pOldACL)
|
2008-04-09 17:49:46 +02:00
|
|
|
{
|
2008-04-11 03:38:50 +02:00
|
|
|
SID_IDENTIFIER_AUTHORITY sidAuth = SECURITY_WORLD_SID_AUTHORITY;
|
2008-04-09 17:49:46 +02:00
|
|
|
PSID pSID = NULL;
|
2008-04-11 03:38:50 +02:00
|
|
|
AllocateAndInitializeSid(&sidAuth, 1, SECURITY_WORLD_RID,
|
2008-04-09 17:49:46 +02:00
|
|
|
0, 0, 0, 0, 0, 0, 0, &pSID);
|
|
|
|
|
|
|
|
EXPLICIT_ACCESS ea;
|
|
|
|
memset(&ea, 0, sizeof(EXPLICIT_ACCESS));
|
|
|
|
ea.grfAccessPermissions = SYNCHRONIZE;
|
|
|
|
ea.grfAccessMode = GRANT_ACCESS;
|
|
|
|
ea.grfInheritance = NO_INHERITANCE;
|
|
|
|
ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
|
|
|
|
ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
|
|
|
|
ea.Trustee.ptstrName = (LPTSTR) pSID;
|
|
|
|
|
|
|
|
PACL pNewACL = NULL;
|
|
|
|
SetEntriesInAcl(1, &ea, pOldACL, &pNewACL);
|
|
|
|
|
2009-08-30 21:00:46 +02:00
|
|
|
SetSecurityInfo(hCurrentProcess, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION,
|
2008-04-09 17:49:46 +02:00
|
|
|
NULL, NULL, pNewACL, NULL);
|
|
|
|
|
|
|
|
if (pSID) {
|
|
|
|
FreeSid(pSID);
|
|
|
|
}
|
|
|
|
if (pNewACL) {
|
|
|
|
LocalFree(pNewACL);
|
2009-09-03 03:18:35 +02:00
|
|
|
}
|
2008-04-09 17:49:46 +02:00
|
|
|
}
|
|
|
|
|
2009-08-30 21:00:46 +02:00
|
|
|
CloseHandle(hCurrentProcess);
|
|
|
|
|
2008-04-10 17:15:09 +02:00
|
|
|
if (pOldSD) {
|
|
|
|
LocalFree(pOldSD);
|
|
|
|
}
|
|
|
|
|
2008-04-09 17:49:46 +02:00
|
|
|
// Create and initialize the default security descriptor
|
|
|
|
// to be assigned to various IPC objects.
|
|
|
|
//
|
|
|
|
// WARNING!!! The absent DACL means full access granted
|
|
|
|
// to everyone, this is a huge security risk!
|
2002-11-25 17:25:31 +01:00
|
|
|
|
2009-03-03 13:26:58 +01:00
|
|
|
PSECURITY_DESCRIPTOR p_security_desc = static_cast<PSECURITY_DESCRIPTOR>(
|
2009-03-01 16:42:23 +01:00
|
|
|
pool.allocate(SECURITY_DESCRIPTOR_MIN_LENGTH));
|
2008-04-09 17:49:46 +02:00
|
|
|
|
|
|
|
attributes.nLength = sizeof(attributes);
|
|
|
|
attributes.lpSecurityDescriptor = p_security_desc;
|
|
|
|
attributes.bInheritHandle = TRUE;
|
|
|
|
|
|
|
|
if (!InitializeSecurityDescriptor(p_security_desc, SECURITY_DESCRIPTOR_REVISION) ||
|
|
|
|
!SetSecurityDescriptorDacl(p_security_desc, TRUE, NULL, FALSE))
|
|
|
|
{
|
2009-03-03 13:26:58 +01:00
|
|
|
pool.deallocate(p_security_desc);
|
2008-04-09 17:49:46 +02:00
|
|
|
attributes.lpSecurityDescriptor = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~SecurityAttributes()
|
|
|
|
{
|
2009-03-03 13:26:58 +01:00
|
|
|
if (attributes.lpSecurityDescriptor)
|
|
|
|
m_pool.deallocate(attributes.lpSecurityDescriptor);
|
2008-04-09 17:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
operator LPSECURITY_ATTRIBUTES()
|
|
|
|
{
|
|
|
|
return attributes.lpSecurityDescriptor ? &attributes : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SECURITY_ATTRIBUTES attributes;
|
2009-03-03 13:26:58 +01:00
|
|
|
MemoryPool& m_pool;
|
2008-04-09 17:49:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static Firebird::InitInstance<SecurityAttributes> security_attributes;
|
|
|
|
|
|
|
|
#endif // WIN_NT
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
|
2002-11-25 17:25:31 +01:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CTYPE_H
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-23 08:31:21 +01:00
|
|
|
// Unix specific stuff
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
#if defined(UNIX)
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/file.h>
|
2003-02-19 07:14:39 +01:00
|
|
|
#ifdef HAVE_PWD_H
|
2001-05-23 15:26:42 +02:00
|
|
|
#include <pwd.h>
|
2003-02-19 07:14:39 +01:00
|
|
|
#endif
|
2002-08-14 13:14:01 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2001-05-23 15:26:42 +02:00
|
|
|
#include <unistd.h>
|
2002-08-14 13:14:01 +02:00
|
|
|
#endif
|
2003-02-19 13:54:39 +01:00
|
|
|
#endif
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
#ifndef O_RDWR
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-02-13 17:47:34 +01:00
|
|
|
bool ISC_check_process_existence(SLONG pid)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I S C _ c h e c k _ p r o c e s s _ e x i s t e n c e
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2009-06-07 11:49:58 +02:00
|
|
|
* Return true if the indicated process
|
|
|
|
* exists; false otherwise.
|
2001-05-23 15:26:42 +02:00
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
|
2008-02-13 17:47:34 +01:00
|
|
|
#ifdef WIN_NT
|
2008-12-11 11:08:35 +01:00
|
|
|
const HANDLE handle = OpenProcess(SYNCHRONIZE, FALSE, (DWORD) pid);
|
2002-11-25 17:25:31 +01:00
|
|
|
|
2008-12-11 11:08:35 +01:00
|
|
|
if (!handle)
|
2002-11-25 17:25:31 +01:00
|
|
|
{
|
2008-12-11 11:08:35 +01:00
|
|
|
return (GetLastError() == ERROR_ACCESS_DENIED);
|
2002-11-25 17:25:31 +01:00
|
|
|
}
|
|
|
|
|
2008-12-11 11:08:35 +01:00
|
|
|
const bool alive = (WaitForSingleObject(handle, 0) != WAIT_OBJECT_0);
|
2002-11-25 17:25:31 +01:00
|
|
|
CloseHandle(handle);
|
2008-12-11 11:08:35 +01:00
|
|
|
return alive;
|
2001-05-23 15:26:42 +02:00
|
|
|
#else
|
2008-02-13 17:47:34 +01:00
|
|
|
return (kill((int) pid, 0) == -1 && errno == ESRCH) ? false : true;
|
2001-05-23 15:26:42 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-15 08:29:00 +02:00
|
|
|
#if defined(SOLARIS)
|
2004-05-29 15:34:54 +02:00
|
|
|
TEXT* ISC_get_host(TEXT* string, USHORT length)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I S C _ g e t _ h o s t ( S O L A R I S )
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Get host name.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
struct utsname name;
|
|
|
|
|
|
|
|
if (uname(&name) >= 0)
|
2004-10-07 11:01:39 +02:00
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
strncpy(string, name.nodename, length);
|
2004-10-07 11:01:39 +02:00
|
|
|
string[length - 1] = 0;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
|
|
|
strcpy(string, "local");
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2004-05-05 23:55:13 +02:00
|
|
|
#elif defined(WIN_NT)
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-05-29 15:34:54 +02:00
|
|
|
TEXT* ISC_get_host(TEXT* string, USHORT length)
|
2002-11-25 17:25:31 +01:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I S C _ g e t _ h o s t ( W I N _ N T )
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Get host name.
|
|
|
|
* Note that this is not the DNS (TCP/IP) hostname,
|
|
|
|
* it's the Win32 computer name.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
DWORD host_len = length;
|
|
|
|
if (GetComputerName(string, &host_len))
|
|
|
|
{
|
|
|
|
string[host_len] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(string, "local");
|
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2004-05-05 23:55:13 +02:00
|
|
|
#else
|
|
|
|
|
2004-05-29 15:34:54 +02:00
|
|
|
TEXT* ISC_get_host(TEXT* string, USHORT length)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I S C _ g e t _ h o s t ( G E N E R I C )
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Get host name.
|
|
|
|
*
|
|
|
|
**************************************/
|
2006-02-23 06:08:26 +01:00
|
|
|
// See http://www.opengroup.org/onlinepubs/007908799/xns/gethostname.html
|
|
|
|
if (gethostname(string, length))
|
|
|
|
string[0] = 0; // failure
|
|
|
|
else
|
|
|
|
string[length - 1] = 0; // truncation doesn't guarantee null termination
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-19 17:18:59 +01:00
|
|
|
const TEXT* ISC_get_host(Firebird::string& host)
|
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I S C _ g e t _ h o s t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Get host name in non-plain buffer.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
TEXT buffer[BUFFER_SMALL];
|
|
|
|
ISC_get_host(buffer, sizeof(buffer));
|
|
|
|
host = buffer;
|
|
|
|
return host.c_str();
|
|
|
|
}
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
#ifdef UNIX
|
2009-11-23 08:31:21 +01:00
|
|
|
bool ISC_get_user(Firebird::string* name, int* id, int* group, const TEXT* user_string)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I S C _ g e t _ u s e r ( U N I X )
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Find out who the user is.
|
|
|
|
*
|
|
|
|
**************************************/
|
2009-11-23 08:31:21 +01:00
|
|
|
// egid and euid need to be signed, uid_t is unsigned on SUN!
|
2001-05-23 15:26:42 +02:00
|
|
|
SLONG egid, euid;
|
2003-11-01 11:26:43 +01:00
|
|
|
TEXT user_name[256];
|
2004-06-05 11:37:18 +02:00
|
|
|
const TEXT* p = 0;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-23 15:26:12 +02:00
|
|
|
if (user_string && *user_string)
|
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
const TEXT* q = user_string;
|
2009-06-04 15:15:41 +02:00
|
|
|
char* un = user_name;
|
|
|
|
while ((*un = *q++) && *un != '.')
|
|
|
|
++un;
|
2004-06-05 11:37:18 +02:00
|
|
|
*un = 0;
|
2001-05-23 15:26:42 +02:00
|
|
|
p = user_name;
|
|
|
|
egid = euid = -1;
|
2005-08-22 09:25:13 +02:00
|
|
|
#ifdef TRUST_CLIENT_VERIFICATION
|
2009-06-23 15:26:12 +02:00
|
|
|
if (*q)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
egid = atoi(q);
|
|
|
|
while (*q && (*q != '.'))
|
|
|
|
q++;
|
2009-06-23 15:26:12 +02:00
|
|
|
if (*q == '.')
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
q++;
|
|
|
|
euid = atoi(q);
|
|
|
|
}
|
|
|
|
}
|
2005-08-22 09:25:13 +02:00
|
|
|
#endif
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-06-23 15:26:12 +02:00
|
|
|
else
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
euid = (SLONG) geteuid();
|
|
|
|
egid = (SLONG) getegid();
|
2003-11-01 11:26:43 +01:00
|
|
|
const struct passwd* password = getpwuid(euid);
|
|
|
|
if (password)
|
|
|
|
p = password->pw_name;
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
|
|
|
p = "";
|
|
|
|
endpwent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name)
|
2007-11-19 17:18:59 +01:00
|
|
|
*name = p;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (id)
|
|
|
|
*id = euid;
|
|
|
|
|
|
|
|
if (group)
|
|
|
|
*group = egid;
|
|
|
|
|
|
|
|
return (euid == 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-11-25 17:25:31 +01:00
|
|
|
#ifdef WIN_NT
|
2009-11-23 08:31:21 +01:00
|
|
|
bool ISC_get_user(Firebird::string* name, int* id, int* group, const TEXT* /*user_string*/)
|
2002-11-25 17:25:31 +01:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I S C _ g e t _ u s e r ( W I N _ N T )
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Find out who the user is.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
if (id)
|
|
|
|
*id = -1;
|
|
|
|
|
|
|
|
if (group)
|
|
|
|
*group = -1;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
2007-11-19 21:34:10 +01:00
|
|
|
DWORD name_len = UNLEN;
|
|
|
|
TEXT* nm = name->getBuffer(name_len + 1);
|
2007-11-19 17:18:59 +01:00
|
|
|
if (GetUserName(nm, &name_len))
|
2002-11-25 17:25:31 +01:00
|
|
|
{
|
2007-11-19 17:18:59 +01:00
|
|
|
nm[name_len] = 0;
|
2002-11-25 17:25:31 +01:00
|
|
|
|
2006-12-08 19:38:15 +01:00
|
|
|
// NT user name is case insensitive
|
2007-11-19 21:34:10 +01:00
|
|
|
CharUpperBuff(nm, name_len);
|
2007-11-19 17:18:59 +01:00
|
|
|
name->recalculate_length();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*name = "";
|
2002-11-25 17:25:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-08 19:38:15 +01:00
|
|
|
return false;
|
2002-11-25 17:25:31 +01:00
|
|
|
}
|
2006-12-08 19:38:15 +01:00
|
|
|
#endif //WIN_NT
|
2003-10-29 11:53:47 +01:00
|
|
|
|
2007-04-05 14:47:20 +02:00
|
|
|
inline void setPrefixIfNotEmpty(const Firebird::PathName& prefix, SSHORT arg_type)
|
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* s e t P r e f i x I f N o t E m p t y
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Helper for ISC_set_prefix
|
|
|
|
*
|
|
|
|
**************************************/
|
2008-12-02 08:09:49 +01:00
|
|
|
if (prefix.hasData())
|
2007-04-05 14:47:20 +02:00
|
|
|
{
|
2008-12-02 08:09:49 +01:00
|
|
|
// ignore here return value of gds__get_prefix():
|
2007-04-05 14:47:20 +02:00
|
|
|
// it will never fail with our good arguments
|
|
|
|
gds__get_prefix(arg_type, prefix.c_str());
|
|
|
|
}
|
|
|
|
}
|
2003-10-29 11:53:47 +01:00
|
|
|
|
2007-04-05 14:47:20 +02:00
|
|
|
SLONG ISC_set_prefix(const TEXT* sw, const TEXT* path)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
2008-12-02 08:09:49 +01:00
|
|
|
* i s c _ s e t _ p r e f i x
|
2001-05-23 15:26:42 +02:00
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2007-04-05 14:47:20 +02:00
|
|
|
* Parse the 'E' argument further for 'EL' 'EM' or 'E'
|
2001-05-23 15:26:42 +02:00
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
|
2008-12-02 08:09:49 +01:00
|
|
|
/*
|
2007-04-05 14:47:20 +02:00
|
|
|
* We can't call gds__get_prefix() at once when switch is found.
|
2009-06-10 10:39:55 +02:00
|
|
|
* gds__get_prefix() invokes GDS_init_prefix(), which in turn causes
|
2007-04-05 14:47:20 +02:00
|
|
|
* config file to be loaded. And in case when -el or -em is given
|
|
|
|
* before -e, this leads to use of wrong firebird.conf.
|
2008-12-02 08:09:49 +01:00
|
|
|
* To avoid it accumulate values for switches locally,
|
2007-04-05 14:47:20 +02:00
|
|
|
* and finally when called with sw==0, use them in correct order.
|
|
|
|
*/
|
2008-03-11 03:05:09 +01:00
|
|
|
static struct ESwitches
|
|
|
|
{
|
2007-04-05 14:47:20 +02:00
|
|
|
Firebird::PathName prefix, lockPrefix, msgPrefix;
|
2008-03-11 03:05:09 +01:00
|
|
|
|
|
|
|
explicit ESwitches(MemoryPool& p)
|
|
|
|
: prefix(p), lockPrefix(p), msgPrefix(p)
|
2009-11-23 08:31:21 +01:00
|
|
|
{ }
|
2007-04-05 14:47:20 +02:00
|
|
|
}* eSw = 0;
|
2008-12-02 08:09:49 +01:00
|
|
|
|
2007-04-05 14:47:20 +02:00
|
|
|
if (! sw)
|
|
|
|
{
|
|
|
|
if (eSw)
|
|
|
|
{
|
|
|
|
setPrefixIfNotEmpty(eSw->prefix, IB_PREFIX_TYPE);
|
|
|
|
setPrefixIfNotEmpty(eSw->lockPrefix, IB_PREFIX_LOCK_TYPE);
|
|
|
|
setPrefixIfNotEmpty(eSw->msgPrefix, IB_PREFIX_MSG_TYPE);
|
|
|
|
|
|
|
|
delete eSw;
|
|
|
|
eSw = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-02 08:09:49 +01:00
|
|
|
|
2007-04-05 14:47:20 +02:00
|
|
|
if ((!path) || (path[0] <= ' '))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2007-04-05 14:47:20 +02:00
|
|
|
if (! eSw)
|
|
|
|
{
|
|
|
|
eSw = FB_NEW(*getDefaultMemoryPool()) ESwitches(*getDefaultMemoryPool());
|
|
|
|
}
|
|
|
|
|
2008-12-02 08:09:49 +01:00
|
|
|
switch (UPPER(*sw))
|
2007-04-05 14:47:20 +02:00
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case '\0':
|
2007-04-05 14:47:20 +02:00
|
|
|
eSw->prefix = path;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case 'L':
|
2007-04-05 14:47:20 +02:00
|
|
|
eSw->lockPrefix = path;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case 'M':
|
2007-04-05 14:47:20 +02:00
|
|
|
eSw->msgPrefix = path;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
default:
|
2007-04-05 14:47:20 +02:00
|
|
|
return -1;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2007-04-05 14:47:20 +02:00
|
|
|
|
|
|
|
return 0;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2003-10-29 11:53:47 +01:00
|
|
|
|
|
|
|
|
2009-08-30 21:00:46 +02:00
|
|
|
#ifdef WIN9X_SUPPORT
|
|
|
|
|
2009-09-03 03:18:35 +02:00
|
|
|
static DWORD os_type = 0;
|
2009-08-30 21:00:46 +02:00
|
|
|
|
|
|
|
// Returns the type of OS: true for NT,
|
|
|
|
// false for the 16-bit based ones (9x/ME, ...).
|
|
|
|
//
|
|
|
|
bool ISC_is_WinNT()
|
|
|
|
{
|
2009-09-03 03:18:35 +02:00
|
|
|
// NS: this is thread safe.
|
2009-08-30 21:00:46 +02:00
|
|
|
// In the worst case initialization will be called more than once
|
|
|
|
if (!os_type)
|
|
|
|
{
|
2009-11-23 08:31:21 +01:00
|
|
|
// The first time this routine is called we use the Windows API
|
|
|
|
// call GetVersion to determine whether Windows NT or 9X
|
|
|
|
// is running.
|
2009-08-30 21:00:46 +02:00
|
|
|
OSVERSIONINFO OsVersionInfo;
|
2009-09-03 03:18:35 +02:00
|
|
|
|
2009-08-30 21:00:46 +02:00
|
|
|
OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
2009-09-02 06:23:02 +02:00
|
|
|
if (GetVersionEx((LPOSVERSIONINFO) &OsVersionInfo))
|
2009-08-30 21:00:46 +02:00
|
|
|
{
|
|
|
|
os_type = OsVersionInfo.dwPlatformId;
|
|
|
|
fb_assert(os_type);
|
2009-09-02 06:23:02 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-09-03 03:18:35 +02:00
|
|
|
os_type = VER_PLATFORM_WIN32_NT; // Default to NT
|
2009-08-30 21:00:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return os_type >= VER_PLATFORM_WIN32_NT; // Windows NT, CE and future platforms
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-02 06:23:02 +02:00
|
|
|
|
2008-02-26 12:03:09 +01:00
|
|
|
#ifdef WIN_NT
|
2002-11-25 17:25:31 +01:00
|
|
|
LPSECURITY_ATTRIBUTES ISC_get_security_desc()
|
|
|
|
{
|
2008-04-09 17:49:46 +02:00
|
|
|
return security_attributes();
|
2002-11-25 17:25:31 +01:00
|
|
|
}
|
2007-02-19 14:05:27 +01:00
|
|
|
#endif
|
2008-09-04 11:58:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
void iscLogStatus(const TEXT* text, const ISC_STATUS* status_vector)
|
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
2009-06-10 10:39:55 +02:00
|
|
|
* i s c L o g S t a t u s
|
2008-09-04 11:58:20 +02:00
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Log error to error log.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
fb_assert(status_vector[1] != FB_SUCCESS);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Firebird::string buffer(text ? text : "");
|
|
|
|
|
|
|
|
TEXT temp[BUFFER_LARGE];
|
|
|
|
while (fb_interpret(temp, sizeof(temp), &status_vector))
|
|
|
|
{
|
2008-09-06 20:42:55 +02:00
|
|
|
if (!buffer.isEmpty())
|
2008-09-04 11:58:20 +02:00
|
|
|
{
|
|
|
|
buffer += "\n\t";
|
|
|
|
}
|
|
|
|
buffer += temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
gds__log("%s", buffer.c_str());
|
|
|
|
}
|
|
|
|
catch (const Firebird::Exception&)
|
|
|
|
{} // no-op
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void iscLogException(const char* text, const Firebird::Exception& e)
|
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
2009-06-10 10:39:55 +02:00
|
|
|
* i s c L o g E x c e p t i o n
|
2008-09-04 11:58:20 +02:00
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Add record about an exception to firebird.log
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
ISC_STATUS_ARRAY s;
|
|
|
|
e.stuff_exception(s);
|
|
|
|
iscLogStatus(text, s);
|
|
|
|
}
|
|
|
|
|