-
Notifications
You must be signed in to change notification settings - Fork 129
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
UAC issues on Windows #40
Comments
Open The plugin has no problems to work then, you don't need to run vagrant as administrator. |
Two windows cmd scripts that can work together to change permissions for the current user to modify the hosts file. win-hosts-check.cmd check if the permissions on the file are sufficient. If not it will call win-hosts-set.cmd which will trigger the windows permission dialog asking for enough rights to midify the permissions on the hosts file for the current user. See issue agiledivider#40
Two windows cmd scripts that can work together to change permissions for the current user to modify the hosts file. win-hosts-check.cmd check if the permissions on the file are sufficient. If not it will call win-hosts-set.cmd which will trigger the windows permission dialog asking for enough rights to midify the permissions on the hosts file for the current user. See issue agiledivider#40
If you want to do that in a semi-automatic fashion, I've created some cmd scripts that are capable of doing so. |
So, I probably should have checked the project issues before working on this, but I've also written a solution. https://github.com/itsananderson/vagrant-hostsupdater The main difference between my workaround and @tkdb's is mine asks for UAC escalation "on-demand" each time it modifies the hosts file, so write permissions on the hosts file aren't changed at all. If we want to use all or part of my solution, I can clean it up for a PR. |
@itsananderson Thanks for the feedback. From quick review I'd say your code is worth for PR (I'm not speaking for the vagrant-hostsupdater project here just my personal opinion as a user and developer), if you can make it into a PR referencing this issue would be great, then I can give it a test-drive here on my box. Edit: Later I spotted Powershell as dependency which is not necessarily part of windows - available checks (as well as fail checks) are missing. |
Two windows cmd scripts that can work together to change permissions for the current user to modify the hosts file. win-hosts-check.cmd check if the permissions on the file are sufficient. If not it will call win-hosts-set.cmd which will trigger the windows permission dialog asking for enough rights to midify the permissions on the hosts file for the current user. See issue agiledivider#40
@itsananderson +1 for removing powershell dependency and PR'ing this. |
I got busy with other things and lost track of this. I think removing the PS dependency should be doable, I just need to find the time to rewrite it. I'll see if I can set aside some time over the next weekend or two. Feel free to ping me if I forget again :) EDIT: Looks like there was already a commit back in November that seems to solve this issue? |
@itsananderson Can you give a pointer to that commit please? Not seeing it in the commit log for this repository. |
Oh, I was wrong. I saw this: willenglishiv@d5b031c and incorrectly thought it was in the original repo. I'll see if I can use that commit as a reference for doing UAC elevation in CMD, so we can get this fix into a PR. |
@itsananderson That'd be great! |
Just ran into this issue, since the last commit to the plugin was 2013 has development on this repo likely stopped for good? Which repo were you going to send the PR to? |
Hmm, @Cogitatio has been totally silent on GitHub for the previous year. Maybe he wouldn't mind if someone took over maintenance? |
Hey @jeremiahsmall I will be maintaining the project for @Cogitatio - I'll be submitting updates shortly. |
Okay. Good to see the project lives. |
👍 |
@itsananderson if youd like to submit a pull request that's be great. Otherwise I'll take a crack at it in a couple weeks. |
I definetly support @itsananderson solution. Do the PR! 👍 I'm currently using the 1.0.1 version from @cgsmith correcting this first start crash. Addressing this issue would make it perfect for Windows users, I guess. |
This should hopefully be a good starting point... if !File.writable_real?(@@hosts_path)
sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
+ elsif Vagrant::Util::Platform.windows?
+ require 'tmpdir'
+ uuid = @machine.id || @machine.config.hostsupdater.id
+ hashedId = Digest::MD5.hexdigest(uuid)
+ tmpPath = File.join(Dir.tmpdir, 'hosts-' + uuid + '.cmd')
+ File.open(tmpPath, "w") do |tmpFile|
+ entries.each { |line| tmpFile.puts(">>\"#{@@hosts_path}\" echo #{line}") }
+ end
+ sudo(tmpPath)
+ File.delete(tmpPath)
else
content = "\n" + content
hostsFile = File.open(@@hosts_path, "a") def sudo(command)
return if !command
+ if Vagrant::Util::Platform.windows?
+ require 'win32ole'
+ args = command.split(" ")
+ command = args.shift
+ sh = WIN32OLE.new('Shell.Application')
+ sh.ShellExecute(command, args.join(" "), '', 'runas', 0)
+ return
+ end
`sudo #{command}`
end |
So far that code above has been working for me. Has no 3rd party dependencies. Works with multiple entries. I think that's probably the way to go. But feel free to test it on your own. If we could get |
Is there any more work to do for this one? I'm willing to help as this would be a really useful addition! |
Hi @oniric85 if you are willing you could pull down the code and test it out on your machine! That would be really useful! Feel free to document what it takes you to get the code running on the wiki or by writing some Markdown - thanks for offering to help! |
I submitted a PR to fix this almost a year ago. I've since moved on to |
Thanks @QWp6t I'd like to have it tested on a Windows machine (I dont have one) and will gladly merge it in if some others can verify it is working. |
On Windows, hostsupdater fails unless vagrant is run as an administrator. Unfortunately, this is really not the smart way to run vagrant. I know you can elevate privileges through WIN32OLE, but I'm not familiar enough with ruby to actually patch it myself. Thoughts?
The text was updated successfully, but these errors were encountered: