aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygserver
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2014-03-12 17:37:04 +0000
committerCorinna Vinschen <corinna@vinschen.de>2014-03-12 17:37:04 +0000
commit600afd99abacfd836b41930c6bc5e014bc5d94e3 (patch)
tree5e2810e59de5df2a595b15a826a0432534b58218 /winsup/cygserver
parent29b7313d2225eb4468170b94f80acc473b06b7ea (diff)
downloadnewlib-600afd99abacfd836b41930c6bc5e014bc5d94e3.zip
newlib-600afd99abacfd836b41930c6bc5e014bc5d94e3.tar.gz
newlib-600afd99abacfd836b41930c6bc5e014bc5d94e3.tar.bz2
* Makefile.in (OBJS): Add pwdgrp.o.
* client.cc (client_request::handle_request): Handle CYGSERVER_REQUEST_PWDGRP message. * pwdgrp.cc: New file implementing CYGSERVER_REQUEST_PWDGRP.
Diffstat (limited to 'winsup/cygserver')
-rw-r--r--winsup/cygserver/ChangeLog7
-rw-r--r--winsup/cygserver/Makefile.in4
-rw-r--r--winsup/cygserver/client.cc4
-rw-r--r--winsup/cygserver/pwdgrp.cc161
4 files changed, 174 insertions, 2 deletions
diff --git a/winsup/cygserver/ChangeLog b/winsup/cygserver/ChangeLog
index f0a9911..b451483 100644
--- a/winsup/cygserver/ChangeLog
+++ b/winsup/cygserver/ChangeLog
@@ -1,5 +1,12 @@
2014-03-12 Corinna Vinschen <corinna@vinschen.de>
+ * Makefile.in (OBJS): Add pwdgrp.o.
+ * client.cc (client_request::handle_request): Handle
+ CYGSERVER_REQUEST_PWDGRP message.
+ * pwdgrp.cc: New file implementing CYGSERVER_REQUEST_PWDGRP.
+
+2014-03-12 Corinna Vinschen <corinna@vinschen.de>
+
* Throughout, fix format specifiers in debug statements to accommodate
x86_64.
diff --git a/winsup/cygserver/Makefile.in b/winsup/cygserver/Makefile.in
index e2fe309..816f5b3 100644
--- a/winsup/cygserver/Makefile.in
+++ b/winsup/cygserver/Makefile.in
@@ -1,5 +1,5 @@
# Makefile for Cygwin server
-# Copyright 2003, 2006, 2007, 2008, 2009 Red Hat, Inc.
+# Copyright 2003, 2006, 2007, 2008, 2009, 2014 Red Hat, Inc.
# This file is part of Cygwin.
@@ -46,7 +46,7 @@ AR:=@AR@
OBJS:= cygserver.o client.o process.o msg.o sem.o shm.o threaded_queue.o \
transport.o transport_pipes.o \
bsd_helper.o bsd_log.o bsd_mutex.o \
- sysv_msg.o sysv_sem.o sysv_shm.o setpwd.o
+ sysv_msg.o sysv_sem.o sysv_shm.o setpwd.o pwdgrp.o
LIBOBJS:=${patsubst %.o,lib%.o,$(OBJS)}
CYGWIN_OBJS:=$(cygwin_build)/version.o
diff --git a/winsup/cygserver/client.cc b/winsup/cygserver/client.cc
index 94e56f3..9775bbc 100644
--- a/winsup/cygserver/client.cc
+++ b/winsup/cygserver/client.cc
@@ -26,6 +26,7 @@ details. */
#include "cygserver_sem.h"
#include "cygserver_shm.h"
#include "cygserver_setpwd.h"
+#include "cygserver_pwdgrp.h"
#include "cygserver.h"
#include "transport.h"
@@ -285,6 +286,9 @@ client_request::handle_request (transport_layer_base *const conn,
case CYGSERVER_REQUEST_SETPWD:
req = new client_request_setpwd;
break;
+ case CYGSERVER_REQUEST_PWDGRP:
+ req = new client_request_pwdgrp;
+ break;
default:
syscall_printf ("unknown request code %d received: request ignored",
header.request_code);
diff --git a/winsup/cygserver/pwdgrp.cc b/winsup/cygserver/pwdgrp.cc
new file mode 100644
index 0000000..90e88ce
--- /dev/null
+++ b/winsup/cygserver/pwdgrp.cc
@@ -0,0 +1,161 @@
+/* pwdgrp.cc: Request account information
+
+ Copyright 2014 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license. Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifdef __OUTSIDE_CYGWIN__
+#include "woutsup.h"
+
+#include <stdio.h>
+#include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+#include <sys/cygwin.h>
+
+#include "cygserver.h"
+#include "process.h"
+#include "transport.h"
+
+#include "cygserver_pwdgrp.h"
+
+#include <sddl.h>
+
+client_request_pwdgrp::client_request_pwdgrp ()
+ : client_request (CYGSERVER_REQUEST_PWDGRP,
+ &_parameters, sizeof (_parameters))
+{
+}
+
+void
+client_request_pwdgrp::pwd_serve ()
+{
+ struct passwd *pwd = NULL;
+
+ switch (_parameters.in.type)
+ {
+ case SID_arg:
+ pwd = (struct passwd *) cygwin_internal (CW_GETPWSID, 0,
+ &_parameters.in.arg.sid);
+ break;
+ case NAME_arg:
+ pwd = getpwnam (_parameters.in.arg.name);
+ break;
+ case ID_arg:
+ pwd = getpwuid (_parameters.in.arg.id);
+ break;
+ }
+ if (pwd)
+ msglen (snprintf (_parameters.out.line, sizeof _parameters.out.line,
+ "%s:%s:%u:%u:%s:%s:%s",
+ pwd->pw_name ?: "",
+ pwd->pw_passwd ?: "",
+ (uint32_t) pwd->pw_uid,
+ (uint32_t) pwd->pw_gid,
+ pwd->pw_gecos ?: "",
+ pwd->pw_dir ?: "",
+ pwd->pw_shell ?: ""));
+ else
+ {
+ switch (_parameters.in.type)
+ {
+ case SID_arg:
+ {
+ char *str;
+ if (ConvertSidToStringSid (&_parameters.in.arg.sid, &str))
+ {
+ debug_printf ("User <%s> failed", str);
+ LocalFree (str);
+ }
+ }
+ break;
+ case NAME_arg:
+ debug_printf ("User <%s> failed", _parameters.in.arg.name);
+ break;
+ case ID_arg:
+ debug_printf ("User <%u> failed", _parameters.in.arg.id);
+ break;
+ }
+ _parameters.out.line[0] = '\0';
+ msglen (0);
+ error_code (ENOENT);
+ }
+}
+
+void
+client_request_pwdgrp::grp_serve ()
+{
+ struct group *grp = NULL;
+
+ switch (_parameters.in.type)
+ {
+ case SID_arg:
+ grp = (struct group *) cygwin_internal (CW_GETGRSID, 0,
+ &_parameters.in.arg.sid);
+ break;
+ case NAME_arg:
+ grp = getgrnam (_parameters.in.arg.name);
+ break;
+ case ID_arg:
+ grp = getgrgid (_parameters.in.arg.id);
+ break;
+ }
+ if (grp)
+ msglen (snprintf (_parameters.out.line, sizeof _parameters.out.line,
+ "%s:%s:%u:",
+ grp->gr_name ?: "",
+ grp->gr_passwd ?: "",
+ (uint32_t) grp->gr_gid));
+ else
+ {
+ switch (_parameters.in.type)
+ {
+ case SID_arg:
+ {
+ char *str;
+ if (ConvertSidToStringSid (&_parameters.in.arg.sid, &str))
+ {
+ debug_printf ("Group <%s> failed", str);
+ LocalFree (str);
+ }
+ }
+ break;
+ case NAME_arg:
+ debug_printf ("Group <%s> failed", _parameters.in.arg.name);
+ break;
+ case ID_arg:
+ debug_printf ("Group <%u> failed", _parameters.in.arg.id);
+ break;
+ }
+ _parameters.out.line[0] = '\0';
+ msglen (0);
+ error_code (ENOENT);
+ }
+}
+
+void
+client_request_pwdgrp::serve (transport_layer_base *const conn,
+ process_cache *const cache)
+{
+ debug_printf ("Request account information");
+ if (msglen () < __builtin_offsetof (struct _pwdgrp_param_t::_pwdgrp_in_t, arg)
+ + sizeof (uint32_t)
+ || msglen () > sizeof (_parameters.in))
+ {
+ syscall_printf ("bad request body length: got %lu", msglen ());
+ error_code (EINVAL);
+ msglen (0);
+ return;
+ }
+ error_code (0);
+ if (_parameters.in.group)
+ grp_serve ();
+ else
+ pwd_serve ();
+ debug_printf ("Request account information returns <%s> error %d", _parameters.out.line, error_code ());
+}
+#endif /* __OUTSIDE_CYGWIN__ */