delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/01/03/15:24:19

From: corinna DOT vinschen AT cityweb DOT de (Corinna Vinschen)
Subject: chown succeed, but SID is wrong!
3 Jan 1999 15:24:19 -0800 :
Message-ID: <368FF53A.D474078F.cygnus.cygwin32.developers@cityweb.de>
Mime-Version: 1.0
To: cygwin32-developers AT cygnus DOT com

Funny:

chown works as expected, with the following exception:

My standalone workstation is named `corinna' and my personal
user account is named `corinna', too. The relative SID is 1000.
If I start the command

	chown corinna foo

and later

	ls -lGn foo

the surprising result is:

	-rwxr-xr-x   1 65535    300396 Jan  1 19:38 foo

instead of

	-rwxr-xr-x   1 1000     300396 Jan  1 19:38 foo

If I look into this files properties in the explorer,
the owner is `unknown'.

I have found, that the function LookupAccountName()
returns the SID for the account corinna, but with the
SID-type indicator set to SidTypeDomain! The function
has returned the SID for the computer, not for the user.
The tool XCACLS.EXE from NTRESKIT has the same error.

I have patched the function chown in syscalls.cc. I'm not sure,
if this is a reasonable solution, but it works for me and I think
it's a good start for e real solution. I have attached the patch.
It only does the following:

If the returned SidType is not SidTypeUser, It calls LookupAccountName()
again, with username set to `returned_domain_name\\username'.

Regards,
Corinna

ChangeLog:
==========
Sun Jan  3 23:20:00 1998  Corinna Vinschen  <corinna DOT vinschen AT cityweb DOT de>

	* syscalls.cc (chown): Retry LookupAccountName with username set
	to domain\\username, if returned SID-Type is not SidTypeUser.

Index: syscalls.cc
===================================================================
RCS file: /src/cvsroot/winsup-981230/syscalls.cc,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 syscalls.cc
--- syscalls.cc 1998/12/30 23:01:58     1.1.1.1
+++ syscalls.cc 1999/01/03 22:16:21
@@ -794,10 +794,14 @@ chown (const char * name, uid_t uid, gid
                  BackupRead (hFile, NULL, 0, &bytes_read, TRUE, TRUE, &context);
                  CloseHandle (hFile);

+                 strcpy(abs_buf, username);
+                 int retried = 0;
+retry:
+
                  /* get sid for the new user */
                  sid_len = 1024;
                  domname_len = 100;
-                 if (!LookupAccountName (NULL, username, psid_name,
+                 if (!LookupAccountName (NULL, abs_buf, psid_name,
                            &sid_len, domain_name, &domname_len, &acc_type))
                    {
                      __seterrno ();
@@ -811,6 +815,16 @@ chown (const char * name, uid_t uid, gid
                      return -1;
                    }

+                 if (acc_type != SidTypeUser
+                     && ! retried
+                     && domain_name && *domain_name)
+                   {
+                      __small_sprintf (abs_buf, "%s\\%s",
+                                       domain_name, username);
+                      retried = 1;
+                      goto retry;
+                   }
+
                  /* convert security descriptor to absolute format */
                  if (!rel2abssd (psd, abs_psd, 1024))
                    {

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019