]>
sourceware.org Git - newlib-cygwin.git/blob - winsup/cygserver/setpwd.cc
70d96cd57b3ab1b5f7ef1012a888409099518510
1 /* setpwd.cc: Set LSA private data password for current user.
3 Copyright 2008 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
11 #ifdef __OUTSIDE_CYGWIN__
26 #include "cygserver.h"
28 #include "transport.h"
30 #include "cygserver_setpwd.h"
32 client_request_setpwd::client_request_setpwd ()
33 : client_request (CYGSERVER_REQUEST_SETPWD
,
34 &_parameters
, sizeof (_parameters
))
39 client_request_setpwd::serve (transport_layer_base
*const conn
,
40 process_cache
*const cache
)
44 WCHAR sidbuf
[128], key_name
[128 + wcslen (CYGWIN_LSA_KEY_PREFIX
)];
45 UNICODE_STRING sid
, key
, data
;
47 syscall_printf ("Request to set private data");
48 if (msglen () != sizeof (_parameters
.in
))
50 syscall_printf ("bad request body length: expecting %lu bytes, got %lu",
51 sizeof (_parameters
), msglen ());
57 if (!conn
->impersonate_client ())
62 if (!OpenThreadToken (GetCurrentThread (), TOKEN_READ
, TRUE
, &tok
))
64 conn
->revert_to_self ();
68 /* Get uid from user SID in token. */
69 user
= (PTOKEN_USER
) get_token_info (tok
, TokenUser
);
71 conn
->revert_to_self ();
77 LSA_OBJECT_ATTRIBUTES oa
= { 0, 0, 0, 0, 0, 0 };
79 NTSTATUS status
= LsaOpenPolicy (NULL
, &oa
, POLICY_CREATE_SECRET
, &lsa
);
80 if (!NT_SUCCESS (status
))
82 error_code (LsaNtStatusToWinError (status
));
85 RtlInitEmptyUnicodeString (&sid
, sidbuf
, sizeof sidbuf
);
86 RtlConvertSidToUnicodeString (&sid
, user
->User
.Sid
, FALSE
);
88 RtlInitEmptyUnicodeString (&key
, key_name
, sizeof key_name
);
89 RtlAppendUnicodeToString (&key
, CYGWIN_LSA_KEY_PREFIX
);
90 RtlAppendUnicodeStringToString (&key
, &sid
);
91 RtlInitUnicodeString (&data
, _parameters
.in
.passwd
);
92 status
= LsaStorePrivateData (lsa
, &key
, data
.Length
? &data
: NULL
);
94 memset (data
.Buffer
, 0, data
.Length
);
95 if (NT_SUCCESS (status
))
98 error_code (LsaNtStatusToWinError (status
));
99 syscall_printf ("Request to set private data returns error %d", error_code ());
102 #endif /* __OUTSIDE_CYGWIN__ */
This page took 0.035672 seconds and 4 git commands to generate.