Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A required privilege is not held by the client #594

Closed
mottosso opened this issue Apr 16, 2019 · 2 comments
Closed

A required privilege is not held by the client #594

mottosso opened this issue Apr 16, 2019 · 2 comments

Comments

@mottosso
Copy link
Contributor

On Windows, as a non-administrator, running rez-bind --quickstart yields the following stack trace.

$ rez-bind --quickstart
Binding platform into C:\Users\me\packages...
16:28:43 WARNING  Skipping installation: Package variant already exists: C:\Users\me\packages\platform\windows\package.py[]
Binding arch into C:\Users\me\packages...
16:28:43 WARNING  Skipping installation: Package variant already exists: C:\Users\me\packages\arch\AMD64\package.py[]
Binding os into C:\Users\me\packages...
16:28:43 WARNING  Skipping installation: Package variant already exists: C:\Users\me\packages\os\windows-10.0.17134\package.py[]
Binding python into C:\Users\me\packages...
Traceback (most recent call last):
  File "c:\Python27\Lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\Python27\Lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\me\Dropbox\dev\anima\rez\Scripts\rez\rez-bind.exe\__main__.py", line 2, in <module>
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\cli\_main.py", line 144, in run
    returncode = run_cmd()
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\cli\_main.py", line 136, in run_cmd
    return opts.func(opts, opts.parser, extra_arg_groups)
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\cli\bind.py", line 75, in command
    quiet=True)
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\package_bind.py", line 112, in bind_package
    quiet=quiet)
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\package_bind.py", line 176, in _bind_package
    parser=bind_parser)
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\bind\python.py", line 86, in bind
    pkg.post_commands = post_commands
  File "c:\Python27\Lib\contextlib.py", line 24, in __exit__
    self.gen.next()
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\package_maker__.py", line 217, in make_package
    make_root(variant_, root)
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\bind\python.py", line 70, in make_root
    platform_.symlink(exepath, link)
  File "c:\users\me\rez\lib\site-packages\rez-2.29.0-py2.7.egg\rez\utils\platform_.py", line 506, in symlink
    raise ctypes.WinError()
WindowsError: [Error 1314] A required privilege is not held by the client.

Related

Presumably, because users on Windows can't (soft) symlink files without administrative privileges.

  • One solution might be to simply not symlink Python, but just copy it.
  • Another is to use hardlink rather than softlink which does work without admin privs, but doesn't work across mounts, e.g. from C:\source.txt to D:\dest.txt.

Temporary Workaround

Here's how I got over this initial hurdle.

  1. Log in as administrator; now your ~/ directory won't point to your user anymore, so rez-bind --quickstart won't actually help install anything there.
  2. As admin, "change" your user. See below.
:: Change user at run-time
$ set USERPROFILE=c:\users\<your-nonprivileged-user>
$ rez-bind --quickstart
$ rez-bind --quickstart
Binding platform into c:\users\me\packages...
Binding arch into c:\users\me\packages...
Binding os into c:\users\me\packages...
Binding python into c:\users\me\packages...
Binding rez into c:\users\me\packages...
Binding rezgui into c:\users\me\packages...
Binding setuptools into c:\users\me\packages...
Binding pip into c:\users\me\packages...

Successfully converted the following software found on the current system into Rez packages:

PACKAGE     URI
-------     ---
arch        c:\users\me\packages\arch\AMD64\package.py
os          c:\users\me\packages\os\windows-10.0.17134\package.py
pip         c:\users\me\packages\pip\1.5.6\package.py
platform    c:\users\me\packages\platform\windows\package.py
python      c:\users\me\packages\python\2.7.14\package.py
rez         c:\users\me\packages\rez\2.29.0\package.py
rezgui      c:\users\me\packages\rezgui\2.29.0\package.py
setuptools  c:\users\me\packages\setuptools\3.6\package.py

To bind other software, see what's available using the command 'rez-bind --list', then run 'rez-bind <name>'.

Now the user has symlink privileges, and will write into the proper directory. However, this still won't work.

Both the python and pip symlinks are broke, because soft symlinks are terrible. So you can:

  1. Copy a system-wide Python, e.g. c:\python27 into ~/packages/python/.../bin, overwriting the soft symlink with a hard copy.
  2. Replace the pip symlink with a .bat file like the one below.

pip.bat

@echo off
python -m pip %*

And presto, it works.

$ rez-env python
> $ python -c  "import sys;print(sys.executable)"
C:\Users\me\packages\python\2.7.14\platform-windows\arch-AMD64\os-windows-10.0.17134\bin\python.exe

In retrospect, I'd probably build and release Python and Pip manually, rather than have --quickstart do it for me. But getting --quickstart to do it shouldn't be an issue if soft symlinks was either replaced with a hard symlink or a plain copy.

@mottosso
Copy link
Contributor Author

Here's an example of hardlinking without admin privileges on Windows.

import ctypes
from ctypes.wintypes import BOOL

CreateHardLink = ctypes.windll.kernel32.CreateHardLinkW
CreateHardLink.restype = BOOL
CreateHardLink.argtypes = [
    ctypes.c_wchar_p,
    ctypes.c_wchar_p,
    ctypes.c_void_p
]

source = "thisfile.txt"
with open(source, "w") as f:
    f.write("")

destination = "thisfile_hard.txt"

if not CreateHardLink(destination, source, None):
    raise ctypes.WinError()

Having said that, hardlinking .exe's like this is unlikely to work anyway, because the .exe will assume the parent directory to be its current working directory, and won't find dynamic libraries relative to it. Python for example wouldn't work this way still, which is a little unfortunate.

Most likely, symlinking of any kind won't work on Windows.

@maltoze
Copy link

maltoze commented Aug 5, 2022

try to enable Developer Mode on windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants