whitespace cleanup, update copyright

This commit is contained in:
Christopher Faylor 2002-03-13 02:34:05 +00:00
parent 2b1c041081
commit 73ea29f42c
21 changed files with 235 additions and 237 deletions

View File

@ -1,6 +1,6 @@
/* cygserver_client.cc /* cygserver_client.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Egor Duda <deo@logos-m.ru> Written by Egor Duda <deo@logos-m.ru>
@ -98,7 +98,7 @@ client_request::send (transport_layer_base *conn)
if ((bytes_read = conn->read ((char *)&header, sizeof (header))) if ((bytes_read = conn->read ((char *)&header, sizeof (header)))
!= sizeof (header) || (header.cb && != sizeof (header) || (header.cb &&
(bytes_read = conn->read (buffer, header.cb) ) != header.cb)) (bytes_read = conn->read (buffer, header.cb)) != header.cb))
{ {
header.error_code = -1; header.error_code = -1;
debug_printf("failed reading response \n"); debug_printf("failed reading response \n");
@ -188,11 +188,11 @@ cygserver_init ()
if (rc < 0) if (rc < 0)
cygserver_running = CYGSERVER_DEAD; cygserver_running = CYGSERVER_DEAD;
else if (rc > 0) else if (rc > 0)
api_fatal ( "error connecting to cygwin server. error: %d", rc ); api_fatal ("error connecting to cygwin server. error: %d", rc);
else if (req->version.major != CYGWIN_SERVER_VERSION_MAJOR || else if (req->version.major != CYGWIN_SERVER_VERSION_MAJOR ||
req->version.api != CYGWIN_SERVER_VERSION_API || req->version.api != CYGWIN_SERVER_VERSION_API ||
req->version.minor > CYGWIN_SERVER_VERSION_MINOR) req->version.minor > CYGWIN_SERVER_VERSION_MINOR)
api_fatal ( "incompatible version of cygwin server.\n\ api_fatal ("incompatible version of cygwin server.\n\
client version %d.%d.%d.%d, server version%ld.%ld.%ld.%ld", client version %d.%d.%d.%d, server version%ld.%ld.%ld.%ld",
CYGWIN_SERVER_VERSION_MAJOR, CYGWIN_SERVER_VERSION_MAJOR,
CYGWIN_SERVER_VERSION_API, CYGWIN_SERVER_VERSION_API,
@ -201,7 +201,7 @@ cygserver_init ()
req->version.major, req->version.major,
req->version.api, req->version.api,
req->version.minor, req->version.minor,
req->version.patch ); req->version.patch);
else else
cygserver_running = CYGSERVER_OK; cygserver_running = CYGSERVER_OK;
} }

View File

@ -1,6 +1,6 @@
/* cygserver.cc /* cygserver.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Egor Duda <deo@logos-m.ru> Written by Egor Duda <deo@logos-m.ru>
@ -47,26 +47,26 @@ setup_privileges ()
HANDLE hToken = NULL; HANDLE hToken = NULL;
TOKEN_PRIVILEGES sPrivileges; TOKEN_PRIVILEGES sPrivileges;
rc = OpenProcessToken ( GetCurrentProcess() , TOKEN_ALL_ACCESS , &hToken ) ; rc = OpenProcessToken (GetCurrentProcess() , TOKEN_ALL_ACCESS , &hToken) ;
if ( !rc ) if (!rc)
{ {
printf ( "error opening process token (%lu)\n", GetLastError () ); printf ("error opening process token (%lu)\n", GetLastError ());
ret_val = FALSE; ret_val = FALSE;
goto out; goto out;
} }
rc = LookupPrivilegeValue ( NULL, SE_DEBUG_NAME, &sPrivileges.Privileges[0].Luid ); rc = LookupPrivilegeValue (NULL, SE_DEBUG_NAME, &sPrivileges.Privileges[0].Luid);
if ( !rc ) if (!rc)
{ {
printf ( "error getting prigilege luid (%lu)\n", GetLastError () ); printf ("error getting prigilege luid (%lu)\n", GetLastError ());
ret_val = FALSE; ret_val = FALSE;
goto out; goto out;
} }
sPrivileges.PrivilegeCount = 1 ; sPrivileges.PrivilegeCount = 1 ;
sPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ; sPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ;
rc = AdjustTokenPrivileges ( hToken, FALSE, &sPrivileges, 0, NULL, NULL ) ; rc = AdjustTokenPrivileges (hToken, FALSE, &sPrivileges, 0, NULL, NULL) ;
if ( !rc ) if (!rc)
{ {
printf ( "error adjusting prigilege level. (%lu)\n", GetLastError () ); printf ("error adjusting prigilege level. (%lu)\n", GetLastError ());
ret_val = FALSE; ret_val = FALSE;
goto out; goto out;
} }
@ -79,16 +79,16 @@ setup_privileges ()
ret_val = TRUE; ret_val = TRUE;
out: out:
CloseHandle ( hToken ); CloseHandle (hToken);
return ret_val; return ret_val;
} }
int int
check_and_dup_handle (HANDLE from_process, HANDLE to_process, check_and_dup_handle (HANDLE from_process, HANDLE to_process,
HANDLE from_process_token, HANDLE from_process_token,
DWORD access, DWORD access,
HANDLE from_handle, HANDLE from_handle,
HANDLE* to_handle_ptr, BOOL bInheritHandle = FALSE) HANDLE* to_handle_ptr, BOOL bInheritHandle = FALSE)
{ {
HANDLE local_handle = NULL; HANDLE local_handle = NULL;
int ret_val = EACCES; int ret_val = EACCES;
@ -100,47 +100,47 @@ check_and_dup_handle (HANDLE from_process, HANDLE to_process,
BOOL status; BOOL status;
if (from_process != GetCurrentProcess ()) if (from_process != GetCurrentProcess ())
{ {
if (!DuplicateHandle (from_process, from_handle, if (!DuplicateHandle (from_process, from_handle,
GetCurrentProcess (), &local_handle, GetCurrentProcess (), &local_handle,
0, bInheritHandle, 0, bInheritHandle,
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
printf ( "error getting handle(%u) to server (%lu)\n", (unsigned int)from_handle, GetLastError ()); printf ("error getting handle(%u) to server (%lu)\n", (unsigned int)from_handle, GetLastError ());
goto out; goto out;
} }
} else } else
local_handle = from_handle; local_handle = from_handle;
if (!GetKernelObjectSecurity (local_handle, if (!GetKernelObjectSecurity (local_handle,
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
sd, sizeof (sd_buf), &bytes_needed)) sd, sizeof (sd_buf), &bytes_needed))
{ {
printf ( "error getting handle SD (%lu)\n", GetLastError ()); printf ("error getting handle SD (%lu)\n", GetLastError ());
goto out; goto out;
} }
MapGenericMask (&access, &access_mapping); MapGenericMask (&access, &access_mapping);
if (!AccessCheck (sd, from_process_token, access, &access_mapping, if (!AccessCheck (sd, from_process_token, access, &access_mapping,
&ps, &ps_len, &access, &status)) &ps, &ps_len, &access, &status))
{ {
printf ( "error checking access rights (%lu)\n", GetLastError ()); printf ("error checking access rights (%lu)\n", GetLastError ());
goto out; goto out;
} }
if (!status) if (!status)
{ {
printf ( "access to object denied\n"); printf ("access to object denied\n");
goto out; goto out;
} }
if (!DuplicateHandle (from_process, from_handle, if (!DuplicateHandle (from_process, from_handle,
to_process, to_handle_ptr, to_process, to_handle_ptr,
access, bInheritHandle, 0)) access, bInheritHandle, 0))
{ {
printf ( "error getting handle to client (%lu)\n", GetLastError ()); printf ("error getting handle to client (%lu)\n", GetLastError ());
goto out; goto out;
} }
debug_printf ("Duplicated %p to %p\n", from_handle, *to_handle_ptr); debug_printf ("Duplicated %p to %p\n", from_handle, *to_handle_ptr);
@ -178,7 +178,7 @@ client_request_attach_tty::serve(transport_layer_base *conn, class process_cache
} }
debug_printf ("pid %ld:(%p,%p) -> pid %ld\n", req.master_pid, debug_printf ("pid %ld:(%p,%p) -> pid %ld\n", req.master_pid,
req.from_master, req.to_master, req.from_master, req.to_master,
req.pid); req.pid);
debug_printf ("opening process %ld\n", req.master_pid); debug_printf ("opening process %ld\n", req.master_pid);
@ -197,8 +197,8 @@ client_request_attach_tty::serve(transport_layer_base *conn, class process_cache
debug_printf ("about to open thread token\n"); debug_printf ("about to open thread token\n");
rc = OpenThreadToken (GetCurrentThread (), rc = OpenThreadToken (GetCurrentThread (),
TOKEN_QUERY, TOKEN_QUERY,
TRUE, TRUE,
&token_handle); &token_handle);
debug_printf ("opened thread token, rc=%lu\n", rc); debug_printf ("opened thread token, rc=%lu\n", rc);
@ -212,10 +212,10 @@ client_request_attach_tty::serve(transport_layer_base *conn, class process_cache
} }
if (check_and_dup_handle (from_process_handle, to_process_handle, if (check_and_dup_handle (from_process_handle, to_process_handle,
token_handle, token_handle,
GENERIC_READ, GENERIC_READ,
req.from_master, req.from_master,
&req.from_master, TRUE) != 0) &req.from_master, TRUE) != 0)
{ {
printf ("error duplicating from_master handle (%lu)\n", GetLastError ()); printf ("error duplicating from_master handle (%lu)\n", GetLastError ());
header.error_code = EACCES; header.error_code = EACCES;
@ -238,7 +238,7 @@ client_request_attach_tty::serve(transport_layer_base *conn, class process_cache
#if DEBUG #if DEBUG
printf ("%ld -> %ld(%p,%p)\n", req.master_pid, req.pid, printf ("%ld -> %ld(%p,%p)\n", req.master_pid, req.pid,
req.from_master, req.to_master); req.from_master, req.to_master);
#endif #endif
header.error_code = 0; header.error_code = 0;
@ -309,7 +309,7 @@ request_loop (LPVOID LpParam)
* _AFTER_ the shutdown request. And sending ourselves a request is ugly * _AFTER_ the shutdown request. And sending ourselves a request is ugly
*/ */
if (new_conn && queue->active) if (new_conn && queue->active)
queue->add (new_conn); queue->add (new_conn);
} }
return 0; return 0;
} }
@ -382,10 +382,10 @@ server_request::process ()
bytes_read = conn->read (req->buffer, req->header.cb); bytes_read = conn->read (req->buffer, req->header.cb);
if (bytes_read != req->header.cb) if (bytes_read != req->header.cb)
{ {
debug_printf ("error reading from connection (%lu)\n", GetLastError ()); debug_printf ("error reading from connection (%lu)\n", GetLastError ());
goto out; goto out;
} }
debug_printf ("got body (%ld)\n",bytes_read); debug_printf ("got body (%ld)\n",bytes_read);
} }
@ -458,10 +458,10 @@ main (int argc, char **argv)
switch (i) switch (i)
{ {
case 's': case 's':
shutdown = 1; shutdown = 1;
break; break;
default: default:
break; break;
/*NOTREACHED*/ /*NOTREACHED*/
} }
@ -489,17 +489,17 @@ main (int argc, char **argv)
char version[200]; char version[200];
/* Cygwin dll release */ /* Cygwin dll release */
snprintf (version, 200, "%d.%d.%d(%d.%d/%d/%d)-(%d.%d.%d.%d) %s", snprintf (version, 200, "%d.%d.%d(%d.%d/%d/%d)-(%d.%d.%d.%d) %s",
cygwin_version.dll_major / 1000, cygwin_version.dll_major / 1000,
cygwin_version.dll_major % 1000, cygwin_version.dll_major % 1000,
cygwin_version.dll_minor, cygwin_version.dll_minor,
cygwin_version.api_major, cygwin_version.api_major,
cygwin_version.api_minor, cygwin_version.api_minor,
cygwin_version.shared_data, cygwin_version.shared_data,
CYGWIN_SERVER_VERSION_MAJOR, CYGWIN_SERVER_VERSION_MAJOR,
CYGWIN_SERVER_VERSION_API, CYGWIN_SERVER_VERSION_API,
CYGWIN_SERVER_VERSION_MINOR, CYGWIN_SERVER_VERSION_MINOR,
CYGWIN_SERVER_VERSION_PATCH, CYGWIN_SERVER_VERSION_PATCH,
cygwin_version.mount_registry, cygwin_version.mount_registry,
cygwin_version.dll_build_date); cygwin_version.dll_build_date);
setbuf (stdout, NULL); setbuf (stdout, NULL);
printf ("daemon version %s starting up", version); printf ("daemon version %s starting up", version);

View File

@ -1,6 +1,6 @@
/* cygserver_process.cc /* cygserver_process.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -117,10 +117,10 @@ process_cache::remove_process (class process *theprocess)
{ {
entry = (class process *) InterlockedExchangePointer (&head, theprocess->next); entry = (class process *) InterlockedExchangePointer (&head, theprocess->next);
if (entry != theprocess) if (entry != theprocess)
{ {
printf ("Bug encountered, process cache corrupted\n"); printf ("Bug encountered, process cache corrupted\n");
exit (1); exit (1);
} }
} }
else else
{ {
@ -138,7 +138,6 @@ process_cache::remove_process (class process *theprocess)
add_task (theprocess); add_task (theprocess);
} }
/* copy <= max_copy HANDLEs to dest[], starting at an offset into _our list_ of /* copy <= max_copy HANDLEs to dest[], starting at an offset into _our list_ of
* begin_at. (Ie begin_at = 5, the first copied handle is still written to dest[0] * begin_at. (Ie begin_at = 5, the first copied handle is still written to dest[0]
* NOTE: Thread safe, but not thread guaranteed - a newly added process may be missed. * NOTE: Thread safe, but not thread guaranteed - a newly added process may be missed.

View File

@ -1,6 +1,6 @@
/* cygserver_shm.cc: Single unix specification IPC interface for Cygwin /* cygserver_shm.cc: Single unix specification IPC interface for Cygwin
Copyright 2001 Red Hat, Inc. Copyright 2001, 2002 Red Hat, Inc.
Originally written by Robert Collins <robert.collins@hotmail.com> Originally written by Robert Collins <robert.collins@hotmail.com>
@ -182,9 +182,9 @@ delete_shmnode (shmnode **nodeptr)
{ {
shmnode *tempnode = shm_head; shmnode *tempnode = shm_head;
while (tempnode && tempnode->next != node) while (tempnode && tempnode->next != node)
tempnode = tempnode->next; tempnode = tempnode->next;
if (tempnode) if (tempnode)
tempnode->next = node->next; tempnode->next = node->next;
// else log the unexpected ! // else log the unexpected !
} }
@ -207,7 +207,7 @@ client_request_shm::serve (transport_layer_base * conn, process_cache * cache)
PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) parameters.in.sd_buf; PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) parameters.in.sd_buf;
// /* create a sd for our open requests based on shmflag & 0x01ff */ // /* create a sd for our open requests based on shmflag & 0x01ff */
// psd = alloc_sd (getuid (), getgid (), cygheap->user.logsrv (), // psd = alloc_sd (getuid (), getgid (), cygheap->user.logsrv (),
// parameters.in.shmflg & 0x01ff, psd, &sd_size); // parameters.in.shmflg & 0x01ff, psd, &sd_size);
HANDLE from_process_handle = NULL; HANDLE from_process_handle = NULL;
HANDLE token_handle = NULL; HANDLE token_handle = NULL;
@ -364,9 +364,9 @@ client_request_shm::serve (transport_layer_base * conn, process_cache * cache)
delete_shmnode (&temp2); delete_shmnode (&temp2);
} }
header.error_code = 0; header.error_code = 0;
CloseHandle (token_handle); CloseHandle (token_handle);
return; return;
} }
tempnode = &(*tempnode)->next; tempnode = &(*tempnode)->next;
} }
@ -623,7 +623,7 @@ client_request_shm::serve (transport_layer_base * conn, process_cache * cache)
/* we now have the area in the daemon list, opened. /* we now have the area in the daemon list, opened.
FIXME: leave the system wide shm mutex */ FIXME: leave the system wide shm mutex */
parameters.out.shm_id = tempnode->shm_id; parameters.out.shm_id = tempnode->shm_id;
if (check_and_dup_handle (GetCurrentProcess (), from_process_handle, if (check_and_dup_handle (GetCurrentProcess (), from_process_handle,

View File

@ -1,6 +1,6 @@
/* cygserver_shm.h /* cygserver_shm.h
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
This file is part of Cygwin. This file is part of Cygwin.

View File

@ -1,6 +1,6 @@
/* cygserver_transport.cc /* cygserver_transport.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>

View File

@ -1,6 +1,6 @@
/* cygserver_transport_pipes.cc /* cygserver_transport_pipes.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -80,11 +80,11 @@ transport_layer_pipes::accept ()
} }
pipe = CreateNamedPipe (pipe_name, pipe = CreateNamedPipe (pipe_name,
PIPE_ACCESS_DUPLEX, PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE | PIPE_WAIT, PIPE_TYPE_BYTE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES, PIPE_UNLIMITED_INSTANCES,
0, 0, 1000, 0, 0, 1000,
&sec_all_nih ); &sec_all_nih );
if (pipe == INVALID_HANDLE_VALUE) if (pipe == INVALID_HANDLE_VALUE)
{ {
debug_printf ("error creating pipe (%lu)\n.", GetLastError ()); debug_printf ("error creating pipe (%lu)\n.", GetLastError ());
@ -164,24 +164,24 @@ transport_layer_pipes::connect ()
while (1) while (1)
{ {
pipe = CreateFile (pipe_name, pipe = CreateFile (pipe_name,
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_all_nih, &sec_all_nih,
OPEN_EXISTING, OPEN_EXISTING,
0, NULL); 0, NULL);
if (pipe != INVALID_HANDLE_VALUE) if (pipe != INVALID_HANDLE_VALUE)
/* got the pipe */ /* got the pipe */
return true; return true;
if (GetLastError () != ERROR_PIPE_BUSY) if (GetLastError () != ERROR_PIPE_BUSY)
{ {
debug_printf ("Error opening the pipe (%lu)\n", GetLastError ()); debug_printf ("Error opening the pipe (%lu)\n", GetLastError ());
pipe = NULL; pipe = NULL;
return false; return false;
} }
if (!WaitNamedPipe (pipe_name, 20000)) if (!WaitNamedPipe (pipe_name, 20000))
debug_printf ( "error connecting to server pipe after 20 seconds (%lu)\n", GetLastError () ); debug_printf ( "error connecting to server pipe after 20 seconds (%lu)\n", GetLastError () );
/* We loop here, because the pipe exists but is busy. If it doesn't exist /* We loop here, because the pipe exists but is busy. If it doesn't exist
* the != ERROR_PIPE_BUSY will catch it. * the != ERROR_PIPE_BUSY will catch it.
*/ */

View File

@ -1,6 +1,6 @@
/* cygserver_transport_sockets.cc /* cygserver_transport_sockets.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -28,7 +28,7 @@ extern "C" int
cygwin_socket (int af, int type, int protocol); cygwin_socket (int af, int type, int protocol);
extern "C" int extern "C" int
cygwin_connect (int fd, cygwin_connect (int fd,
const struct sockaddr *name, const struct sockaddr *name,
int namelen); int namelen);
extern "C" int extern "C" int
cygwin_accept (int fd, struct sockaddr *peer, int *len); cygwin_accept (int fd, struct sockaddr *peer, int *len);

View File

@ -1,6 +1,6 @@
/* cygserver.cc /* cygserver.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Egor Duda <deo@logos-m.ru> Written by Egor Duda <deo@logos-m.ru>
@ -47,26 +47,26 @@ setup_privileges ()
HANDLE hToken = NULL; HANDLE hToken = NULL;
TOKEN_PRIVILEGES sPrivileges; TOKEN_PRIVILEGES sPrivileges;
rc = OpenProcessToken ( GetCurrentProcess() , TOKEN_ALL_ACCESS , &hToken ) ; rc = OpenProcessToken (GetCurrentProcess() , TOKEN_ALL_ACCESS , &hToken) ;
if ( !rc ) if (!rc)
{ {
printf ( "error opening process token (%lu)\n", GetLastError () ); printf ("error opening process token (%lu)\n", GetLastError ());
ret_val = FALSE; ret_val = FALSE;
goto out; goto out;
} }
rc = LookupPrivilegeValue ( NULL, SE_DEBUG_NAME, &sPrivileges.Privileges[0].Luid ); rc = LookupPrivilegeValue (NULL, SE_DEBUG_NAME, &sPrivileges.Privileges[0].Luid);
if ( !rc ) if (!rc)
{ {
printf ( "error getting prigilege luid (%lu)\n", GetLastError () ); printf ("error getting prigilege luid (%lu)\n", GetLastError ());
ret_val = FALSE; ret_val = FALSE;
goto out; goto out;
} }
sPrivileges.PrivilegeCount = 1 ; sPrivileges.PrivilegeCount = 1 ;
sPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ; sPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ;
rc = AdjustTokenPrivileges ( hToken, FALSE, &sPrivileges, 0, NULL, NULL ) ; rc = AdjustTokenPrivileges (hToken, FALSE, &sPrivileges, 0, NULL, NULL) ;
if ( !rc ) if (!rc)
{ {
printf ( "error adjusting prigilege level. (%lu)\n", GetLastError () ); printf ("error adjusting prigilege level. (%lu)\n", GetLastError ());
ret_val = FALSE; ret_val = FALSE;
goto out; goto out;
} }
@ -79,16 +79,16 @@ setup_privileges ()
ret_val = TRUE; ret_val = TRUE;
out: out:
CloseHandle ( hToken ); CloseHandle (hToken);
return ret_val; return ret_val;
} }
int int
check_and_dup_handle (HANDLE from_process, HANDLE to_process, check_and_dup_handle (HANDLE from_process, HANDLE to_process,
HANDLE from_process_token, HANDLE from_process_token,
DWORD access, DWORD access,
HANDLE from_handle, HANDLE from_handle,
HANDLE* to_handle_ptr, BOOL bInheritHandle = FALSE) HANDLE* to_handle_ptr, BOOL bInheritHandle = FALSE)
{ {
HANDLE local_handle = NULL; HANDLE local_handle = NULL;
int ret_val = EACCES; int ret_val = EACCES;
@ -100,47 +100,47 @@ check_and_dup_handle (HANDLE from_process, HANDLE to_process,
BOOL status; BOOL status;
if (from_process != GetCurrentProcess ()) if (from_process != GetCurrentProcess ())
{ {
if (!DuplicateHandle (from_process, from_handle, if (!DuplicateHandle (from_process, from_handle,
GetCurrentProcess (), &local_handle, GetCurrentProcess (), &local_handle,
0, bInheritHandle, 0, bInheritHandle,
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
printf ( "error getting handle(%u) to server (%lu)\n", (unsigned int)from_handle, GetLastError ()); printf ("error getting handle(%u) to server (%lu)\n", (unsigned int)from_handle, GetLastError ());
goto out; goto out;
} }
} else } else
local_handle = from_handle; local_handle = from_handle;
if (!GetKernelObjectSecurity (local_handle, if (!GetKernelObjectSecurity (local_handle,
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
sd, sizeof (sd_buf), &bytes_needed)) sd, sizeof (sd_buf), &bytes_needed))
{ {
printf ( "error getting handle SD (%lu)\n", GetLastError ()); printf ("error getting handle SD (%lu)\n", GetLastError ());
goto out; goto out;
} }
MapGenericMask (&access, &access_mapping); MapGenericMask (&access, &access_mapping);
if (!AccessCheck (sd, from_process_token, access, &access_mapping, if (!AccessCheck (sd, from_process_token, access, &access_mapping,
&ps, &ps_len, &access, &status)) &ps, &ps_len, &access, &status))
{ {
printf ( "error checking access rights (%lu)\n", GetLastError ()); printf ("error checking access rights (%lu)\n", GetLastError ());
goto out; goto out;
} }
if (!status) if (!status)
{ {
printf ( "access to object denied\n"); printf ("access to object denied\n");
goto out; goto out;
} }
if (!DuplicateHandle (from_process, from_handle, if (!DuplicateHandle (from_process, from_handle,
to_process, to_handle_ptr, to_process, to_handle_ptr,
access, bInheritHandle, 0)) access, bInheritHandle, 0))
{ {
printf ( "error getting handle to client (%lu)\n", GetLastError ()); printf ("error getting handle to client (%lu)\n", GetLastError ());
goto out; goto out;
} }
debug_printf ("Duplicated %p to %p\n", from_handle, *to_handle_ptr); debug_printf ("Duplicated %p to %p\n", from_handle, *to_handle_ptr);
@ -178,7 +178,7 @@ client_request_attach_tty::serve(transport_layer_base *conn, class process_cache
} }
debug_printf ("pid %ld:(%p,%p) -> pid %ld\n", req.master_pid, debug_printf ("pid %ld:(%p,%p) -> pid %ld\n", req.master_pid,
req.from_master, req.to_master, req.from_master, req.to_master,
req.pid); req.pid);
debug_printf ("opening process %ld\n", req.master_pid); debug_printf ("opening process %ld\n", req.master_pid);
@ -197,8 +197,8 @@ client_request_attach_tty::serve(transport_layer_base *conn, class process_cache
debug_printf ("about to open thread token\n"); debug_printf ("about to open thread token\n");
rc = OpenThreadToken (GetCurrentThread (), rc = OpenThreadToken (GetCurrentThread (),
TOKEN_QUERY, TOKEN_QUERY,
TRUE, TRUE,
&token_handle); &token_handle);
debug_printf ("opened thread token, rc=%lu\n", rc); debug_printf ("opened thread token, rc=%lu\n", rc);
@ -212,10 +212,10 @@ client_request_attach_tty::serve(transport_layer_base *conn, class process_cache
} }
if (check_and_dup_handle (from_process_handle, to_process_handle, if (check_and_dup_handle (from_process_handle, to_process_handle,
token_handle, token_handle,
GENERIC_READ, GENERIC_READ,
req.from_master, req.from_master,
&req.from_master, TRUE) != 0) &req.from_master, TRUE) != 0)
{ {
printf ("error duplicating from_master handle (%lu)\n", GetLastError ()); printf ("error duplicating from_master handle (%lu)\n", GetLastError ());
header.error_code = EACCES; header.error_code = EACCES;
@ -238,7 +238,7 @@ client_request_attach_tty::serve(transport_layer_base *conn, class process_cache
#if DEBUG #if DEBUG
printf ("%ld -> %ld(%p,%p)\n", req.master_pid, req.pid, printf ("%ld -> %ld(%p,%p)\n", req.master_pid, req.pid,
req.from_master, req.to_master); req.from_master, req.to_master);
#endif #endif
header.error_code = 0; header.error_code = 0;
@ -309,7 +309,7 @@ request_loop (LPVOID LpParam)
* _AFTER_ the shutdown request. And sending ourselves a request is ugly * _AFTER_ the shutdown request. And sending ourselves a request is ugly
*/ */
if (new_conn && queue->active) if (new_conn && queue->active)
queue->add (new_conn); queue->add (new_conn);
} }
return 0; return 0;
} }
@ -382,10 +382,10 @@ server_request::process ()
bytes_read = conn->read (req->buffer, req->header.cb); bytes_read = conn->read (req->buffer, req->header.cb);
if (bytes_read != req->header.cb) if (bytes_read != req->header.cb)
{ {
debug_printf ("error reading from connection (%lu)\n", GetLastError ()); debug_printf ("error reading from connection (%lu)\n", GetLastError ());
goto out; goto out;
} }
debug_printf ("got body (%ld)\n",bytes_read); debug_printf ("got body (%ld)\n",bytes_read);
} }
@ -458,10 +458,10 @@ main (int argc, char **argv)
switch (i) switch (i)
{ {
case 's': case 's':
shutdown = 1; shutdown = 1;
break; break;
default: default:
break; break;
/*NOTREACHED*/ /*NOTREACHED*/
} }
@ -489,17 +489,17 @@ main (int argc, char **argv)
char version[200]; char version[200];
/* Cygwin dll release */ /* Cygwin dll release */
snprintf (version, 200, "%d.%d.%d(%d.%d/%d/%d)-(%d.%d.%d.%d) %s", snprintf (version, 200, "%d.%d.%d(%d.%d/%d/%d)-(%d.%d.%d.%d) %s",
cygwin_version.dll_major / 1000, cygwin_version.dll_major / 1000,
cygwin_version.dll_major % 1000, cygwin_version.dll_major % 1000,
cygwin_version.dll_minor, cygwin_version.dll_minor,
cygwin_version.api_major, cygwin_version.api_major,
cygwin_version.api_minor, cygwin_version.api_minor,
cygwin_version.shared_data, cygwin_version.shared_data,
CYGWIN_SERVER_VERSION_MAJOR, CYGWIN_SERVER_VERSION_MAJOR,
CYGWIN_SERVER_VERSION_API, CYGWIN_SERVER_VERSION_API,
CYGWIN_SERVER_VERSION_MINOR, CYGWIN_SERVER_VERSION_MINOR,
CYGWIN_SERVER_VERSION_PATCH, CYGWIN_SERVER_VERSION_PATCH,
cygwin_version.mount_registry, cygwin_version.mount_registry,
cygwin_version.dll_build_date); cygwin_version.dll_build_date);
setbuf (stdout, NULL); setbuf (stdout, NULL);
printf ("daemon version %s starting up", version); printf ("daemon version %s starting up", version);

View File

@ -1,6 +1,6 @@
/* cygserver_client.cc /* cygserver_client.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Egor Duda <deo@logos-m.ru> Written by Egor Duda <deo@logos-m.ru>
@ -98,7 +98,7 @@ client_request::send (transport_layer_base *conn)
if ((bytes_read = conn->read ((char *)&header, sizeof (header))) if ((bytes_read = conn->read ((char *)&header, sizeof (header)))
!= sizeof (header) || (header.cb && != sizeof (header) || (header.cb &&
(bytes_read = conn->read (buffer, header.cb) ) != header.cb)) (bytes_read = conn->read (buffer, header.cb)) != header.cb))
{ {
header.error_code = -1; header.error_code = -1;
debug_printf("failed reading response \n"); debug_printf("failed reading response \n");
@ -188,11 +188,11 @@ cygserver_init ()
if (rc < 0) if (rc < 0)
cygserver_running = CYGSERVER_DEAD; cygserver_running = CYGSERVER_DEAD;
else if (rc > 0) else if (rc > 0)
api_fatal ( "error connecting to cygwin server. error: %d", rc ); api_fatal ("error connecting to cygwin server. error: %d", rc);
else if (req->version.major != CYGWIN_SERVER_VERSION_MAJOR || else if (req->version.major != CYGWIN_SERVER_VERSION_MAJOR ||
req->version.api != CYGWIN_SERVER_VERSION_API || req->version.api != CYGWIN_SERVER_VERSION_API ||
req->version.minor > CYGWIN_SERVER_VERSION_MINOR) req->version.minor > CYGWIN_SERVER_VERSION_MINOR)
api_fatal ( "incompatible version of cygwin server.\n\ api_fatal ("incompatible version of cygwin server.\n\
client version %d.%d.%d.%d, server version%ld.%ld.%ld.%ld", client version %d.%d.%d.%d, server version%ld.%ld.%ld.%ld",
CYGWIN_SERVER_VERSION_MAJOR, CYGWIN_SERVER_VERSION_MAJOR,
CYGWIN_SERVER_VERSION_API, CYGWIN_SERVER_VERSION_API,
@ -201,7 +201,7 @@ cygserver_init ()
req->version.major, req->version.major,
req->version.api, req->version.api,
req->version.minor, req->version.minor,
req->version.patch ); req->version.patch);
else else
cygserver_running = CYGSERVER_OK; cygserver_running = CYGSERVER_OK;
} }

View File

@ -1,6 +1,6 @@
/* cygserver_process.cc /* cygserver_process.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -117,10 +117,10 @@ process_cache::remove_process (class process *theprocess)
{ {
entry = (class process *) InterlockedExchangePointer (&head, theprocess->next); entry = (class process *) InterlockedExchangePointer (&head, theprocess->next);
if (entry != theprocess) if (entry != theprocess)
{ {
printf ("Bug encountered, process cache corrupted\n"); printf ("Bug encountered, process cache corrupted\n");
exit (1); exit (1);
} }
} }
else else
{ {
@ -138,7 +138,6 @@ process_cache::remove_process (class process *theprocess)
add_task (theprocess); add_task (theprocess);
} }
/* copy <= max_copy HANDLEs to dest[], starting at an offset into _our list_ of /* copy <= max_copy HANDLEs to dest[], starting at an offset into _our list_ of
* begin_at. (Ie begin_at = 5, the first copied handle is still written to dest[0] * begin_at. (Ie begin_at = 5, the first copied handle is still written to dest[0]
* NOTE: Thread safe, but not thread guaranteed - a newly added process may be missed. * NOTE: Thread safe, but not thread guaranteed - a newly added process may be missed.

View File

@ -1,6 +1,6 @@
/* cygserver_shm.cc: Single unix specification IPC interface for Cygwin /* cygserver_shm.cc: Single unix specification IPC interface for Cygwin
Copyright 2001 Red Hat, Inc. Copyright 2001, 2002 Red Hat, Inc.
Originally written by Robert Collins <robert.collins@hotmail.com> Originally written by Robert Collins <robert.collins@hotmail.com>
@ -182,9 +182,9 @@ delete_shmnode (shmnode **nodeptr)
{ {
shmnode *tempnode = shm_head; shmnode *tempnode = shm_head;
while (tempnode && tempnode->next != node) while (tempnode && tempnode->next != node)
tempnode = tempnode->next; tempnode = tempnode->next;
if (tempnode) if (tempnode)
tempnode->next = node->next; tempnode->next = node->next;
// else log the unexpected ! // else log the unexpected !
} }
@ -207,7 +207,7 @@ client_request_shm::serve (transport_layer_base * conn, process_cache * cache)
PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) parameters.in.sd_buf; PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) parameters.in.sd_buf;
// /* create a sd for our open requests based on shmflag & 0x01ff */ // /* create a sd for our open requests based on shmflag & 0x01ff */
// psd = alloc_sd (getuid (), getgid (), cygheap->user.logsrv (), // psd = alloc_sd (getuid (), getgid (), cygheap->user.logsrv (),
// parameters.in.shmflg & 0x01ff, psd, &sd_size); // parameters.in.shmflg & 0x01ff, psd, &sd_size);
HANDLE from_process_handle = NULL; HANDLE from_process_handle = NULL;
HANDLE token_handle = NULL; HANDLE token_handle = NULL;
@ -364,9 +364,9 @@ client_request_shm::serve (transport_layer_base * conn, process_cache * cache)
delete_shmnode (&temp2); delete_shmnode (&temp2);
} }
header.error_code = 0; header.error_code = 0;
CloseHandle (token_handle); CloseHandle (token_handle);
return; return;
} }
tempnode = &(*tempnode)->next; tempnode = &(*tempnode)->next;
} }
@ -623,7 +623,7 @@ client_request_shm::serve (transport_layer_base * conn, process_cache * cache)
/* we now have the area in the daemon list, opened. /* we now have the area in the daemon list, opened.
FIXME: leave the system wide shm mutex */ FIXME: leave the system wide shm mutex */
parameters.out.shm_id = tempnode->shm_id; parameters.out.shm_id = tempnode->shm_id;
if (check_and_dup_handle (GetCurrentProcess (), from_process_handle, if (check_and_dup_handle (GetCurrentProcess (), from_process_handle,

View File

@ -1,6 +1,6 @@
/* cygserver_shm.h /* cygserver_shm.h
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
This file is part of Cygwin. This file is part of Cygwin.

View File

@ -1,6 +1,6 @@
/* cygserver_transport.cc /* cygserver_transport.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>

View File

@ -1,6 +1,6 @@
/* cygserver_transport_pipes.cc /* cygserver_transport_pipes.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -80,11 +80,11 @@ transport_layer_pipes::accept ()
} }
pipe = CreateNamedPipe (pipe_name, pipe = CreateNamedPipe (pipe_name,
PIPE_ACCESS_DUPLEX, PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE | PIPE_WAIT, PIPE_TYPE_BYTE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES, PIPE_UNLIMITED_INSTANCES,
0, 0, 1000, 0, 0, 1000,
&sec_all_nih ); &sec_all_nih );
if (pipe == INVALID_HANDLE_VALUE) if (pipe == INVALID_HANDLE_VALUE)
{ {
debug_printf ("error creating pipe (%lu)\n.", GetLastError ()); debug_printf ("error creating pipe (%lu)\n.", GetLastError ());
@ -164,24 +164,24 @@ transport_layer_pipes::connect ()
while (1) while (1)
{ {
pipe = CreateFile (pipe_name, pipe = CreateFile (pipe_name,
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_all_nih, &sec_all_nih,
OPEN_EXISTING, OPEN_EXISTING,
0, NULL); 0, NULL);
if (pipe != INVALID_HANDLE_VALUE) if (pipe != INVALID_HANDLE_VALUE)
/* got the pipe */ /* got the pipe */
return true; return true;
if (GetLastError () != ERROR_PIPE_BUSY) if (GetLastError () != ERROR_PIPE_BUSY)
{ {
debug_printf ("Error opening the pipe (%lu)\n", GetLastError ()); debug_printf ("Error opening the pipe (%lu)\n", GetLastError ());
pipe = NULL; pipe = NULL;
return false; return false;
} }
if (!WaitNamedPipe (pipe_name, 20000)) if (!WaitNamedPipe (pipe_name, 20000))
debug_printf ( "error connecting to server pipe after 20 seconds (%lu)\n", GetLastError () ); debug_printf ( "error connecting to server pipe after 20 seconds (%lu)\n", GetLastError () );
/* We loop here, because the pipe exists but is busy. If it doesn't exist /* We loop here, because the pipe exists but is busy. If it doesn't exist
* the != ERROR_PIPE_BUSY will catch it. * the != ERROR_PIPE_BUSY will catch it.
*/ */

View File

@ -1,6 +1,6 @@
/* cygserver_transport_sockets.cc /* cygserver_transport_sockets.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -28,7 +28,7 @@ extern "C" int
cygwin_socket (int af, int type, int protocol); cygwin_socket (int af, int type, int protocol);
extern "C" int extern "C" int
cygwin_connect (int fd, cygwin_connect (int fd,
const struct sockaddr *name, const struct sockaddr *name,
int namelen); int namelen);
extern "C" int extern "C" int
cygwin_accept (int fd, struct sockaddr *peer, int *len); cygwin_accept (int fd, struct sockaddr *peer, int *len);

View File

@ -1,6 +1,6 @@
/* cygserver.h /* cygserver.h
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Egor Duda <deo@logos-m.ru> Written by Egor Duda <deo@logos-m.ru>

View File

@ -1,6 +1,6 @@
/* cygserver_process.h /* cygserver_process.h
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>

View File

@ -1,6 +1,6 @@
/* cygserver.cc /* cygserver.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>

View File

@ -1,6 +1,6 @@
/* cygserver.cc /* cygserver.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>

View File

@ -1,6 +1,6 @@
/* cygserver.cc /* cygserver.cc
Copyright 2001 Red Hat Inc. Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>