diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2011-04-04 13:04:00 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2011-04-04 13:04:00 +0400 |
commit | 1db2e3fbfb556c1890f6590838076e17924947d3 (patch) | |
tree | 5ddb463b86118440b634bfaba33ebcd6c2d6b233 /winsup/cygwin/setlsapwd.cc | |
parent | 225b37131a8eded38ab2420740accf7465f8f7b0 (diff) |
* cygserver_setpwd.h (setlsapwd): Add username parameter to declaration.
* external.cc (cygwin_internal): In the CW_SET_PRIV_KEY case, fetch
additional username parameter.
* setlsapwd.cc (setlsapwd): Add username parameter. Allow admin to
set the hidden password for other users.
Diffstat (limited to 'winsup/cygwin/setlsapwd.cc')
-rw-r--r-- | winsup/cygwin/setlsapwd.cc | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/winsup/cygwin/setlsapwd.cc b/winsup/cygwin/setlsapwd.cc index 7622de370..8e1baa9bb 100644 --- a/winsup/cygwin/setlsapwd.cc +++ b/winsup/cygwin/setlsapwd.cc @@ -1,6 +1,6 @@ /* setlsapwd.cc: Set LSA private data password for current user. - Copyright 2008, 2009 Red Hat, Inc. + Copyright 2008, 2009, 2011 Red Hat, Inc. This file is part of Cygwin. @@ -17,6 +17,7 @@ details. */ #include "cygheap.h" #include "security.h" #include "cygserver_setpwd.h" +#include "pwdgrp.h" #include "ntdll.h" #include <ntsecapi.h> #include <stdlib.h> @@ -37,7 +38,7 @@ client_request_setpwd::client_request_setpwd (PUNICODE_STRING passwd) } unsigned long -setlsapwd (const char *passwd) +setlsapwd (const char *passwd, const char *username) { unsigned long ret = (unsigned long) -1; HANDLE lsa = INVALID_HANDLE_VALUE; @@ -47,8 +48,21 @@ setlsapwd (const char *passwd) UNICODE_STRING key; UNICODE_STRING data; - wcpcpy (wcpcpy (key_name, CYGWIN_LSA_KEY_PREFIX), - cygheap->user.get_windows_id (sid)); + if (username) + { + cygsid psid; + struct passwd *pw = internal_getpwnam (username, false); + + if (!pw || !psid.getfrompw (pw)) + { + set_errno (ENOENT); + return ret; + } + wcpcpy (wcpcpy (key_name, CYGWIN_LSA_KEY_PREFIX), psid.string (sid)); + } + else + wcpcpy (wcpcpy (key_name, CYGWIN_LSA_KEY_PREFIX), + cygheap->user.get_windows_id (sid)); RtlInitUnicodeString (&key, key_name); if (!passwd || ! *passwd || sys_mbstowcs_alloc (&data_buf, HEAP_NOTHEAP, passwd)) @@ -71,7 +85,7 @@ setlsapwd (const char *passwd) __seterrno_from_nt_status (status); LsaClose (lsa); } - else if (ret) + else if (ret && !username) { client_request_setpwd request (&data); if (request.make_request () == -1 || request.error_code ()) |