* net.cc (getdomainname): Change second argument of getdomainname to size_t.

* fhandler_proc.cc (proc_listing): Add '.' and '..' to directory listing.
(fhandler_proc::open): Change use of mode to flags.  If the file does not exist
already, fail with EROFS if O_CREAT flag is set.  Change EROFS error to EACCES
error when writing to a file.  Use cmalloc to allocate memory for filebuf.
(fhandler_proc::close): Use cfree to free filebuf.
(fhandler_proc::get_proc_fhandler): Properly detect attempts to access unknown
subdir.
* fhandler_process.cc (process_listing): Add '.' and '..' to directory listing.
(fhandler_process::open): Use cmalloc to allocate memory for filebuf.
(fhandler_process::close): Use cfree to free filebuf.
* fhandler_registry.cc (registry_listing): Add .  and '..' to directory
listing.
(fhandler_registry::open): Move check for open for writing before open_key.
Use cmalloc to allocate memory for filebuf.
(fhandler_registry::close): Use cfree to free filebuf.
(fhandler_registry::telldir): Use lower 16 bits of __d_position as position in
directory.
(fhandler_registry::seekdir): Ditto.
* fhandler_virtual.cc (fhandler_virtual::write): Change EROFS error to EACCES
error.
(fhandler_virtual::open): Set the NOHANDLE flag.
(fhandler_virtual::dup): Add call to fhandler_base::dup.  Allocate child's
filebuf using cmalloc.  Copy filebuf from parent to child.
(fhandler_virtual::close): Use cfree to free filebuf.
(fhandler_virtual::~fhandler_virtual): Ditto.
(from Chris Faylor <cgf@redhat.com>).
(fhandler_registry::readdir): Add support for '.' and '..' files in
subdirectories of /proc/registry.
* path.cc (path_conv::check): Do not return ENOENT if a file is not found in
/proc.
This commit is contained in:
Christopher Faylor
2002-05-04 03:24:35 +00:00
parent 4b3f6588fb
commit 8761c1dcf7
7 changed files with 167 additions and 65 deletions

View File

@ -20,6 +20,8 @@ details. */
#include "security.h"
#include "fhandler.h"
#include "path.h"
#include "dtable.h"
#include "cygheap.h"
#include <assert.h>
#define _COMPILING_NEWLIB
@ -32,12 +34,16 @@ static const int registry_len = sizeof ("registry") - 1;
* make up the value index if we are enuerating values.
*/
static const __off32_t REG_ENUM_VALUES_MASK = 0x8000000;
static const __off32_t REG_POSITION_MASK = 0xffff;
/* List of root keys in /proc/registry.
* Possibly we should filter out those not relevant to the flavour of Windows
* Cygwin is running on.
*/
static const char *registry_listing[] = {
static const char *registry_listing[] =
{
".",
"..",
"HKEY_CLASSES_ROOT",
"HKEY_CURRENT_CONFIG",
"HKEY_CURRENT_USER",
@ -48,7 +54,10 @@ static const char *registry_listing[] = {
NULL
};
static const HKEY registry_keys[] = {
static const HKEY registry_keys[] =
{
(HKEY) INVALID_HANDLE_VALUE,
(HKEY) INVALID_HANDLE_VALUE,
HKEY_CLASSES_ROOT,
HKEY_CURRENT_CONFIG,
HKEY_CURRENT_USER,
@ -60,6 +69,19 @@ static const HKEY registry_keys[] = {
static const int ROOT_KEY_COUNT = sizeof(registry_keys) / sizeof(HKEY);
/* These get added to each subdirectory in /proc/registry.
* If we wanted to implement writing, we could maybe add a '.writable' entry or
* suchlike.
*/
static const char *special_dot_files[] =
{
".",
"..",
NULL
};
static const int SPECIAL_DOT_FILE_COUNT = (sizeof(special_dot_files) / sizeof(const char *)) - 1;
/* Name given to default values */
static const char *DEFAULT_VALUE_NAME = "@";
@ -213,6 +235,12 @@ fhandler_registry::readdir (DIR * dir)
}
if (dir->__d_u.__d_data.__handle == INVALID_HANDLE_VALUE)
goto out;
if (dir->__d_position < SPECIAL_DOT_FILE_COUNT)
{
strcpy (dir->__d_dirent->d_name, special_dot_files[dir->__d_position++]);
res = dir->__d_dirent;
goto out;
}
retry:
if (dir->__d_position & REG_ENUM_VALUES_MASK)
/* For the moment, the type of key is ignored here. when write access is added,
@ -223,8 +251,8 @@ retry:
buf, &buf_size, NULL, NULL, NULL, NULL);
else
error =
RegEnumKeyEx ((HKEY) dir->__d_u.__d_data.__handle, dir->__d_position,
buf, &buf_size, NULL, NULL, NULL, NULL);
RegEnumKeyEx ((HKEY) dir->__d_u.__d_data.__handle, dir->__d_position -
SPECIAL_DOT_FILE_COUNT, buf, &buf_size, NULL, NULL, NULL, NULL);
if (error == ERROR_NO_MORE_ITEMS
&& (dir->__d_position & REG_ENUM_VALUES_MASK) == 0)
{
@ -260,7 +288,7 @@ out:
__off64_t
fhandler_registry::telldir (DIR * dir)
{
return dir->__d_position & REG_ENUM_VALUES_MASK;
return dir->__d_position & REG_POSITION_MASK;
}
void
@ -270,7 +298,7 @@ fhandler_registry::seekdir (DIR * dir, __off32_t loc)
* values.
*/
rewinddir (dir);
while (loc > dir->__d_position)
while (loc > (dir->__d_position & REG_POSITION_MASK))
if (!readdir (dir))
break;
}
@ -318,13 +346,13 @@ fhandler_registry::open (path_conv *pc, int flags, mode_t mode)
path = get_name () + proc_len + 1 + registry_len;
if (!*path)
{
if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
{
set_errno (EEXIST);
res = 0;
goto out;
}
else if (mode & O_WRONLY)
else if (flags & O_WRONLY)
{
set_errno (EISDIR);
res = 0;
@ -351,13 +379,13 @@ fhandler_registry::open (path_conv *pc, int flags, mode_t mode)
if (path_prefix_p
(registry_listing[i], path, strlen (registry_listing[i])))
{
if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
{
set_errno (EEXIST);
res = 0;
goto out;
}
else if (mode & O_WRONLY)
else if (flags & O_WRONLY)
{
set_errno (EISDIR);
res = 0;
@ -370,7 +398,7 @@ fhandler_registry::open (path_conv *pc, int flags, mode_t mode)
}
}
if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
if (flags & O_CREAT)
{
set_errno (EROFS);
res = 0;
@ -384,15 +412,16 @@ fhandler_registry::open (path_conv *pc, int flags, mode_t mode)
}
}
hKey = open_key (path, KEY_READ, true);
if (hKey == (HKEY) INVALID_HANDLE_VALUE)
if (flags & O_WRONLY)
{
set_errno (EROFS);
res = 0;
goto out;
}
if (mode & O_WRONLY)
hKey = open_key (path, KEY_READ, true);
if (hKey == (HKEY) INVALID_HANDLE_VALUE)
{
set_errno (EROFS);
res = 0;
goto out;
}
@ -409,7 +438,7 @@ fhandler_registry::open (path_conv *pc, int flags, mode_t mode)
goto out;
}
bufalloc = size;
filebuf = new char[bufalloc];
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc);
error =
RegQueryValueEx (hKey, file, NULL, NULL, (BYTE *) filebuf, &size);
if (error != ERROR_SUCCESS)
@ -428,8 +457,8 @@ fhandler_registry::open (path_conv *pc, int flags, mode_t mode)
bufalloc += 1000;
if (filebuf)
{
delete filebuf;
filebuf = new char[bufalloc];
cfree (filebuf);
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc);
}
error =
RegQueryValueEx (hKey, file, NULL, &type, (BYTE *) filebuf,