boxen-linux 2.7.6 → 2.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be8374e7b08b7564045c4e533b49ac2c02349473
4
- data.tar.gz: 649f600117e2ea95b3e7ecae1ee2a3caf3c119ab
3
+ metadata.gz: baea85246dc667baf0cda296a36147eb266c16bb
4
+ data.tar.gz: 8753de721944c194938fe451d32ec3b8e7959649
5
5
  SHA512:
6
- metadata.gz: 9624129e368ac6df5021151256a0b1a4f7063131c44d638041abda57bd5e60335a0447ae5050043eb352bcbfeb5c2d8fc0b4bcb520c9e7709a80dd393480ae35
7
- data.tar.gz: 4744d0b1054d85cfba5e2f46c76580da88e9ba1414f4ca8d765a52f9773aa2d615fce68e16789beef6606993ad7b59a2764078805c9cbb1b0317a7053b9359d1
6
+ metadata.gz: 0838f3581fd5716cc276dc0b077d4571a34cef6d28e7f65789ef3631f33fd976616d843680a1545931b02fdf71578786fa183b57d6cbd28b786bc0c59c14ea30
7
+ data.tar.gz: 8bcd15870867d512cf0e3cdd39ca1b69c058389e596e757f791094c6357b00bbd1d798f9267e9d1ed55350f80a803b24abf3f7d658438163a3c1b5291bcd260a
data/.gitignore CHANGED
@@ -1,11 +1,12 @@
1
1
  /.bundle
2
2
  /.env.local.rb
3
+ /.project
3
4
  /.projects
4
5
  /.rbenv-version
6
+ /.ruby-version
5
7
  /Gemfile.lock
6
8
  /bin
7
9
  /boxen-*.gem
8
10
  /log
9
11
  /puppet
10
12
  /script/Boxen.dSYM
11
- /.ruby-version
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "boxen-linux"
5
- gem.version = "2.7.6"
5
+ gem.version = "2.7.8"
6
6
  gem.authors = ["John Barnette", "Will Farrington", "David Goodlad", "Max Klein"]
7
7
  gem.email = ["jbarnette@github.com", "wfarr@github.com", "dgoodlad@github.com", "mklein@jhu.edu"]
8
8
  gem.description = "Manage Mac and Linux development boxes with love (and Puppet)."
@@ -1,3 +1,4 @@
1
+ require "etc"
1
2
  require "shellwords"
2
3
 
3
4
  module Boxen
@@ -8,7 +9,8 @@ module Boxen
8
9
  if (/darwin/ =~ RUBY_PLATFORM) != nil
9
10
  HELPER = File.expand_path "../../../script/Boxen", __FILE__
10
11
  else
11
- HELPER = File.expand_path "../../../script/Boxen-linux", __FILE__
12
+ HELPER_ENV = File.expand_path "../../../script/keyring-env", __FILE__
13
+ HELPER = File.expand_path "../../../script/Boxen-keyring", __FILE__
12
14
  end
13
15
 
14
16
  # The service name to use when loading/saving passwords.
@@ -39,16 +41,45 @@ module Boxen
39
41
 
40
42
  def get(service)
41
43
  cmd = shellescape(HELPER, service, login)
42
-
43
- result = `#{cmd}`.strip
44
- $?.success? ? result : nil
44
+ if (/darwin/ =~ RUBY_PLATFORM) != nil
45
+ result = `#{cmd}`.strip
46
+ else
47
+ # have to run gnome-keyring commands as user, running as root causes error
48
+ if ENV['USER'] == login
49
+ result = `#{cmd}`.strip
50
+ elsif ENV['USER'] == 'root'
51
+ # dbus env variable has to be set in order to talk to gnome-keyring
52
+ cmd_env = shellescape(HELPER_ENV)
53
+ ENV['DBUS_SESSION_BUS_ADDRESS'] = `#{cmd_env}`.strip
54
+ result = backticks_as_user(login, cmd).strip
55
+ else
56
+ raise Boxen::Error, "User id is set to #{ENV['USER']}, but have to be self or root in order to interact with the keyring."
57
+ end
58
+ end
59
+ $?.success? ? result : nil
45
60
  end
46
61
 
47
62
  def set(service, token)
48
63
  cmd = shellescape(HELPER, service, login, token)
49
-
50
- unless system *cmd
51
- raise Boxen::Error, "Can't save #{service} in the keychain."
64
+ if (/darwin/ =~ RUBY_PLATFORM) != nil
65
+ unless system *cmd
66
+ raise Boxen::Error, "Can't save #{service} in the keychain."
67
+ end
68
+ else
69
+ # have to run gnome-keyring commands as user, running as root causes errors
70
+ if ENV['USER'] == login
71
+ result = system *cmd
72
+ elsif ENV['USER'] == 'root'
73
+ # dbus env variable has to be set in order to talk to gnome-keyring
74
+ cmd_env = shellescape(HELPER_ENV)
75
+ ENV['DBUS_SESSION_BUS_ADDRESS'] = `#{cmd_env}`.strip
76
+ result = system_as_user(login, cmd)
77
+ else
78
+ raise Boxen::Error, "User id is set to #{ENV['USER']}, but have to be self or root in order to interact with the keyring."
79
+ end
80
+ unless result
81
+ raise Boxen::Error, "Can't save #{service} in the keyring."
82
+ end
52
83
  end
53
84
 
54
85
  token
@@ -57,5 +88,42 @@ module Boxen
57
88
  def shellescape(*args)
58
89
  args.map { |s| Shellwords.shellescape s }.join " "
59
90
  end
91
+
92
+ def system_as_user(user, cmd)
93
+ # Find the user in the password database.
94
+ u = (user.is_a? Integer) ? Etc.getpwuid(user) : Etc.getpwnam(user)
95
+
96
+ # Fork the child process. Process.fork will run a set of tokens as a bash command
97
+ # in the child process.
98
+ Process.fork do
99
+ # We're in the child. Set the process's user ID.
100
+ #Process.uid = u.uid
101
+ Process::Sys.setuid(u.uid)
102
+ # Invoke the caller's bash tokens
103
+ system *cmd
104
+ end
105
+ Process.wait
106
+ $?.exitstatus
107
+ end
108
+
109
+ def backticks_as_user(user, cmd)
110
+ u = (user.is_a? Integer) ? Etc.getpwuid(user) : Etc.getpwnam(user)
111
+
112
+ # may the armpits of the ruby and gnome devs be infested with the fleas of a thousand camels!
113
+ # all of the IO.pipe stuff is so that the parent and child forks can talk to each other
114
+ rd, wr = IO.pipe
115
+ Process.fork do
116
+ rd.close
117
+ Process::Sys.setuid(u.uid)
118
+ result = `#{cmd}`
119
+ wr.write result
120
+ wr.close
121
+ end
122
+ wr.close
123
+ result = rd.read
124
+ rd.close
125
+ Process.wait
126
+ result
127
+ end
60
128
  end
61
129
  end
File without changes
@@ -6,4 +6,4 @@
6
6
  set -e
7
7
 
8
8
  cd $(dirname "$0")/..
9
- cc -g -O2 -Wall `pkg-config --cflags glib-2.0 gnome-keyring-1`-o script/Boxen-linux src/keyring-helper.c `pkg-config --libs glib-2.0 gnome-keyring-1`
9
+ cc -g -O2 -Wall `pkg-config --cflags glib-2.0 gnome-keyring-1`-o script/Boxen-keyring src/keyring-helper.c `pkg-config --libs glib-2.0 gnome-keyring-1`
@@ -0,0 +1,43 @@
1
+ #!/bin/bash
2
+ # set up user environment so that the gnome-keyring stuff will actually work.
3
+ # if running this script directly, run with `source keyring-env` so that the export statement works correctly
4
+
5
+ # if dbus is already running get its environment variables. if it's not running start it
6
+ # some of this is taken from http://ubuntuforums.org/showthread.php?t=1059023
7
+ DBUS_PID=$(pidof -s dbus-daemon)
8
+ if [[ "${DBUS_PID}" != "" ]]; then
9
+ # Search these processes for the session variable
10
+ # (they are run as the current user and have the DBUS session variable set)
11
+ compatiblePrograms=( nautilus kdeinit kded4 pulseaudio trackerd )
12
+
13
+ # Attempt to get a program pid
14
+ for index in ${compatiblePrograms[@]}; do
15
+ PID=$(pidof -s ${index})
16
+ if [[ "${PID}" != "" ]]; then
17
+ break
18
+ fi
19
+ done
20
+ if [[ "${PID}" == "" ]]; then
21
+ echo "keyring-env could not detect active login session" 1>&2
22
+ return 1
23
+ fi
24
+
25
+ QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
26
+ if [[ "${QUERY_ENVIRON}" != "" ]]; then
27
+ export DBUS_SESSION_BUS_ADDRESS="${QUERY_ENVIRON}"
28
+ echo "${DBUS_SESSION_BUS_ADDRESS}"
29
+ else
30
+ echo "keyring-env could not find dbus session ID in user environment." 1>&2
31
+ return 1
32
+ fi
33
+ else
34
+ : # put stuff to start dbus and get environment vars here
35
+ fi
36
+
37
+ # make sure that the gnome-keyring-daemon is actually running, and start it if it's not
38
+ GNOME_KEYRING_PID=$(pidof -s gnome-keyring-daemon)
39
+ if [[ "${GNOME_KEYRING_PID}" != "" ]]; then
40
+ : # gnome-keyring-daemon is running, so we don't need to do anything
41
+ else
42
+ : # put stuff to start gnome-keyring-daemon here
43
+ fi
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxen-linux
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.6
4
+ version: 2.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-08-17 00:00:00.000000000 Z
14
+ date: 2014-08-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: ansi
@@ -197,10 +197,11 @@ files:
197
197
  - lib/facter/boxen.rb
198
198
  - lib/system_timer.rb
199
199
  - script/Boxen
200
- - script/Boxen-linux
200
+ - script/Boxen-keyring
201
201
  - script/bootstrap
202
202
  - script/build-keychain-helper
203
203
  - script/build-keyring-helper
204
+ - script/keyring-env
204
205
  - script/release
205
206
  - script/tests
206
207
  - src/keychain-helper.c