* autoload.cc (GetSecurityInfo): Define new autoload function.

(RegQueryInfoKeyA): Ditto.
* fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool.
(fhandler_proc::fill_filebuf): Ditto.
(fhandler_registry::fill_filebuf): Ditto.
(fhandler_process::fill_filebuf): Ditto.
(fhandler_registry::value_name): Add new member.
(fhandler_registry::close): Add new method.
(fhandler_process::p): Remove member.
* fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling
superclass method.  Check return value of fill_filebuf.
(fhandler_proc::fill_filebuf): Change return type to bool.  Add return
statement.
* fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling
superclass method.  Remove references to p.  Check return value of
fill_filebuf.
(fhandler_process::fill_filebuf): Change return type to bool.  Don't use
dereference operator on p.  Add return statement.
(fhandler_process::format_process_stat): Fix typo.
* fhandler_registry.cc: Add static open_key declaration.
(fhandler_registry::exists): Assume path is already normalised.  Try opening
the path as a key in its own right first, before reverting to enumerating
subkeys and values of the parent key.
(fhandler_registry::fstat): Add additional code to return more relevant
information about the registry key/value.
(fhandler_registry::readdir): Explicitly set desired access when opening
registry key.  Remove output of buf from debug_printf format string.
(fhandler_registry::open): Use set_io_handle to store registry key handle.  Set
value_name member.  Move code to read a value from the registry to
fill_filebuf.  Add call to fill_filebuf.
(fhandler_registry::close): New method.
(fhandler_registry::fill_filebuf): Change return type to bool.  Add code to
read a value from registry.
(fhandler_registry::open_key): Make function static.  Use KEY_READ as desired
access unless this is the last path component.  Check the return value of
RegOpenKeyEx for an error instead of hKey.
* fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of
fill_filebuf.
(fhandler_virtual::open): Remove call to set_nohandle.
(fhandler_virtual::fill_filebuf): Change return type to bool.  Add return
statement.
* security.cc (get_nt_object_attribute): New function.
(get_object_attribute): New function.
* security.h (get_object_attribute): New function declaration.
This commit is contained in:
Christopher Faylor
2002-07-02 01:36:15 +00:00
parent cc81f456ac
commit 74fcdaec20
9 changed files with 508 additions and 153 deletions

View File

@ -41,7 +41,8 @@ static const int PROCESS_CTTY = 11;
static const int PROCESS_STAT = 12;
static const int PROCESS_STATM = 13;
static const char *process_listing[] = {
static const char * const process_listing[] =
{
".",
"..",
"ppid",
@ -59,14 +60,17 @@ static const char *process_listing[] = {
NULL
};
static const int PROCESS_LINK_COUNT = (sizeof(process_listing) / sizeof(const char *)) - 1;
static const int PROCESS_LINK_COUNT =
(sizeof(process_listing) / sizeof(const char *)) - 1;
static off_t format_process_stat (_pinfo *p, char *destbuf, size_t maxsize);
static off_t format_process_status (_pinfo *p, char *destbuf, size_t maxsize);
static off_t format_process_statm (_pinfo *p, char *destbuf, size_t maxsize);
static int get_process_state (DWORD dwProcessId);
static bool get_mem_values(DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss, unsigned long *vmtext,
unsigned long *vmdata, unsigned long *vmlib, unsigned long *vmshare);
static bool get_mem_values(DWORD dwProcessId, unsigned long *vmsize,
unsigned long *vmrss, unsigned long *vmtext,
unsigned long *vmdata, unsigned long *vmlib,
unsigned long *vmshare);
/* Returns 0 if path doesn't exist, >0 if path is a directory,
* <0 if path is a file.
@ -159,6 +163,8 @@ fhandler_process::open (path_conv *pc, int flags, mode_t mode)
if (!res)
goto out;
set_nohandle (true);
const char *path;
path = get_name () + proc_len + 1;
pid = atoi (path);
@ -215,25 +221,17 @@ fhandler_process::open (path_conv *pc, int flags, mode_t mode)
goto out;
}
{
pinfo p (pid);
if (!p)
{
set_errno (ENOENT);
res = 0;
goto out;
}
fileid = process_file_no;
this->p = &p;
fill_filebuf ();
if (!fill_filebuf ())
{
res = 0;
goto out;
}
if (flags & O_APPEND)
position = filesize;
else
position = 0;
this->p = NULL;
}
success:
res = 1;
@ -244,20 +242,17 @@ out:
return res;
}
void
bool
fhandler_process::fill_filebuf ()
{
pinfo pmaybe;
pinfo p (pid);
if (!p)
{
pmaybe.init (pid);
p = &pmaybe;
set_errno (ENOENT);
return false;
}
if (!p)
return;
switch (fileid)
{
case PROCESS_UID:
@ -268,27 +263,27 @@ fhandler_process::fill_filebuf ()
case PROCESS_PPID:
{
if (!filebuf)
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40);
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40);
int num;
switch (fileid)
{
case PROCESS_PPID:
num = (*p)->ppid;
num = p->ppid;
break;
case PROCESS_UID:
num = (*p)->uid;
num = p->uid;
break;
case PROCESS_PGID:
num = (*p)->pgid;
num = p->pgid;
break;
case PROCESS_SID:
num = (*p)->sid;
num = p->sid;
break;
case PROCESS_GID:
num = (*p)->gid;
num = p->gid;
break;
case PROCESS_CTTY:
num = (*p)->ctty;
num = p->ctty;
break;
default: // what's this here for?
num = 0;
@ -301,12 +296,12 @@ fhandler_process::fill_filebuf ()
case PROCESS_EXENAME:
{
if (!filebuf)
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = MAX_PATH);
if ((*p)->process_state & (PID_ZOMBIE | PID_EXITED))
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = MAX_PATH);
if (p->process_state & (PID_ZOMBIE | PID_EXITED))
strcpy (filebuf, "<defunct>");
else
{
mount_table->conv_to_posix_path ((*p)->progname, filebuf, 1);
mount_table->conv_to_posix_path (p->progname, filebuf, 1);
int len = strlen (filebuf);
if (len > 4)
{
@ -321,17 +316,17 @@ fhandler_process::fill_filebuf ()
case PROCESS_WINPID:
{
if (!filebuf)
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40);
__small_sprintf (filebuf, "%d\n", (*p)->dwProcessId);
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40);
__small_sprintf (filebuf, "%d\n", p->dwProcessId);
filesize = strlen (filebuf);
break;
}
case PROCESS_WINEXENAME:
{
int len = strlen ((*p)->progname);
int len = strlen (p->progname);
if (!filebuf)
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = (len + 2));
strcpy (filebuf, (*p)->progname);
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = (len + 2));
strcpy (filebuf, p->progname);
filebuf[len] = '\n';
filesize = len + 1;
break;
@ -340,27 +335,26 @@ fhandler_process::fill_filebuf ()
{
if (!filebuf)
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048);
filesize = format_process_status ((*p), filebuf, bufalloc);
filesize = format_process_status (*p, filebuf, bufalloc);
break;
}
case PROCESS_STAT:
{
if (!filebuf)
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048);
filesize = format_process_stat ((*p), filebuf, bufalloc);
filesize = format_process_stat (*p, filebuf, bufalloc);
break;
}
case PROCESS_STATM:
{
if (!filebuf)
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048);
filesize = format_process_statm ((*p), filebuf, bufalloc);
filesize = format_process_statm (*p, filebuf, bufalloc);
break;
}
}
if (p == &pmaybe)
p = NULL;
return true;
}
static
@ -375,7 +369,7 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize)
vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL;
int priority = 0;
if (p->process_state & (PID_ZOMBIE | PID_EXITED))
strcpy (cmd, "<defunct");
strcpy (cmd, "<defunct>");
else
{
strcpy(cmd, p->progname);
@ -598,11 +592,12 @@ static
off_t
format_process_statm (_pinfo *p, char *destbuf, size_t maxsize)
{
unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL, vmlib = 0UL,
vmshare = 0UL;
unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL,
vmlib = 0UL, vmshare = 0UL;
if (wincap.is_winnt ())
{
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata, &vmlib, &vmshare))
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
&vmlib, &vmshare))
return 0;
}
return __small_sprintf (destbuf, "%ld %ld %ld %ld %ld %ld %ld",