* 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.
This commit is contained in:
Corinna Vinschen 2014-03-12 17:37:04 +00:00
parent 29b7313d22
commit 600afd99ab
4 changed files with 174 additions and 2 deletions

View File

@ -1,3 +1,10 @@
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> 2014-03-12 Corinna Vinschen <corinna@vinschen.de>
* Throughout, fix format specifiers in debug statements to accommodate * Throughout, fix format specifiers in debug statements to accommodate

View File

@ -1,5 +1,5 @@
# Makefile for Cygwin server # 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. # 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 \ OBJS:= cygserver.o client.o process.o msg.o sem.o shm.o threaded_queue.o \
transport.o transport_pipes.o \ transport.o transport_pipes.o \
bsd_helper.o bsd_log.o bsd_mutex.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)} LIBOBJS:=${patsubst %.o,lib%.o,$(OBJS)}
CYGWIN_OBJS:=$(cygwin_build)/version.o CYGWIN_OBJS:=$(cygwin_build)/version.o

View File

@ -26,6 +26,7 @@ details. */
#include "cygserver_sem.h" #include "cygserver_sem.h"
#include "cygserver_shm.h" #include "cygserver_shm.h"
#include "cygserver_setpwd.h" #include "cygserver_setpwd.h"
#include "cygserver_pwdgrp.h"
#include "cygserver.h" #include "cygserver.h"
#include "transport.h" #include "transport.h"
@ -285,6 +286,9 @@ client_request::handle_request (transport_layer_base *const conn,
case CYGSERVER_REQUEST_SETPWD: case CYGSERVER_REQUEST_SETPWD:
req = new client_request_setpwd; req = new client_request_setpwd;
break; break;
case CYGSERVER_REQUEST_PWDGRP:
req = new client_request_pwdgrp;
break;
default: default:
syscall_printf ("unknown request code %d received: request ignored", syscall_printf ("unknown request code %d received: request ignored",
header.request_code); header.request_code);

161
winsup/cygserver/pwdgrp.cc Normal file
View File

@ -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__ */