rosxauth 1.0.0
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.
- data/AUTHORS +1 -0
- data/COPYING +0 -0
- data/ChangeLog +0 -0
- data/README.rdoc +0 -0
- data/ext/extconf.rb +12 -0
- data/ext/rosxauth.c +200 -0
- data/ext/rosxauth.h +24 -0
- data/lib/rosxauth/version.rb +3 -0
- data/test/test.rb +43 -0
- metadata +70 -0
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Grégoire Lejeune <gregoire.lejeune@free.fr>
|
data/COPYING
ADDED
File without changes
|
data/ChangeLog
ADDED
File without changes
|
data/README.rdoc
ADDED
File without changes
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Loads mkmf which is used to make makefiles for Ruby extensions
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
# Give it a name
|
5
|
+
extension_name = 'rosxauth'
|
6
|
+
|
7
|
+
# The destination
|
8
|
+
dir_config(extension_name)
|
9
|
+
|
10
|
+
# Do the work
|
11
|
+
$LDFLAGS << ' -framework Cocoa'
|
12
|
+
create_makefile(extension_name)
|
data/ext/rosxauth.c
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
#include "rosxauth.h"
|
2
|
+
|
3
|
+
// The initialization method for this module
|
4
|
+
void Init_rosxauth() {
|
5
|
+
cROSXAuth = rb_define_class("ROSXAuth", rb_cObject);
|
6
|
+
eROSXAuthError = rb_define_class_under( cROSXAuth, "Error", rb_eRuntimeError );
|
7
|
+
|
8
|
+
|
9
|
+
rb_define_singleton_method( cROSXAuth, "new", rosxauth_new, 0 );
|
10
|
+
rb_define_method( cROSXAuth, "status", rosxauth_status, 0 );
|
11
|
+
rb_define_method( cROSXAuth, "auth", rosxauth_auth, 0 );
|
12
|
+
rb_define_method( cROSXAuth, "auth?", rosxauth_auth_q, 0 );
|
13
|
+
rb_define_method( cROSXAuth, "exec", rosxauth_exec, 2 );
|
14
|
+
|
15
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationSuccess", INT2NUM( errAuthorizationSuccess ) );
|
16
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationInvalidSet", INT2NUM( errAuthorizationInvalidSet ) );
|
17
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationInvalidRef", INT2NUM( errAuthorizationInvalidRef ) );
|
18
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationInvalidTag", INT2NUM( errAuthorizationInvalidTag ) );
|
19
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationInvalidPointer", INT2NUM( errAuthorizationInvalidPointer ) );
|
20
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationDenied", INT2NUM( errAuthorizationDenied ) );
|
21
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationCanceled", INT2NUM( errAuthorizationCanceled ) );
|
22
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationInteractionNotAllowed", INT2NUM( errAuthorizationInteractionNotAllowed ) );
|
23
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationInternal", INT2NUM( errAuthorizationInternal ) );
|
24
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationExternalizeNotAllowed", INT2NUM( errAuthorizationExternalizeNotAllowed ) );
|
25
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationInternalizeNotAllowed", INT2NUM( errAuthorizationInternalizeNotAllowed ) );
|
26
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationInvalidFlags", INT2NUM( errAuthorizationInvalidFlags ) );
|
27
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationToolExecuteFailure", INT2NUM( errAuthorizationToolExecuteFailure ) );
|
28
|
+
rb_define_const( cROSXAuth, "ErrAuthorizationToolEnvironmentError", INT2NUM( errAuthorizationToolEnvironmentError ) );
|
29
|
+
}
|
30
|
+
|
31
|
+
/* ------------------------------------------------------------------------------- */
|
32
|
+
|
33
|
+
void rosxauth_free( RbTROSXAuth *pRbTROSXAuth ) {
|
34
|
+
if (pRbTROSXAuth != NULL)
|
35
|
+
free(pRbTROSXAuth);
|
36
|
+
}
|
37
|
+
|
38
|
+
void rosxauth_mark( RbTROSXAuth *pRbTROSXAuth ) {
|
39
|
+
if( pRbTROSXAuth == NULL ) return;
|
40
|
+
AuthorizationFree(pRbTROSXAuth->myAuthorizationRef,kAuthorizationFlagDestroyRights);
|
41
|
+
if( !NIL_P(pRbTROSXAuth->rbAuth) ) rb_gc_mark(pRbTROSXAuth->rbAuth);
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
* Create a new ROSXAuth object
|
46
|
+
*
|
47
|
+
* a = ROSXAuth.new()
|
48
|
+
*/
|
49
|
+
VALUE rosxauth_new( VALUE class ) {
|
50
|
+
RbTROSXAuth *pRbTROSXAuth;
|
51
|
+
|
52
|
+
pRbTROSXAuth = (RbTROSXAuth *)malloc(sizeof(RbTROSXAuth));
|
53
|
+
if( pRbTROSXAuth == NULL )
|
54
|
+
rb_raise(rb_eNoMemError, "No memory left for ROSXAuth struct");
|
55
|
+
|
56
|
+
pRbTROSXAuth->rbAuth = Qfalse;
|
57
|
+
pRbTROSXAuth->myStatus = AuthorizationCreate(
|
58
|
+
NULL,
|
59
|
+
kAuthorizationEmptyEnvironment,
|
60
|
+
kAuthorizationFlagDefaults,
|
61
|
+
&pRbTROSXAuth->myAuthorizationRef);
|
62
|
+
|
63
|
+
return( Data_Wrap_Struct( class, rosxauth_mark, rosxauth_free, pRbTROSXAuth ) );
|
64
|
+
}
|
65
|
+
|
66
|
+
/* ------------------------------------------------------------------------------- */
|
67
|
+
|
68
|
+
/*
|
69
|
+
* Give the authorization status
|
70
|
+
*
|
71
|
+
* r = a.status
|
72
|
+
*/
|
73
|
+
VALUE rosxauth_status(VALUE self) {
|
74
|
+
RbTROSXAuth *pRbTROSXAuth;
|
75
|
+
Data_Get_Struct(self, RbTROSXAuth, pRbTROSXAuth);
|
76
|
+
|
77
|
+
return INT2NUM(pRbTROSXAuth->myStatus);
|
78
|
+
}
|
79
|
+
|
80
|
+
/*
|
81
|
+
* Authorizes and preauthorizes rights.
|
82
|
+
*
|
83
|
+
* a.auth
|
84
|
+
*/
|
85
|
+
VALUE rosxauth_auth(VALUE self) {
|
86
|
+
RbTROSXAuth *pRbTROSXAuth;
|
87
|
+
Data_Get_Struct(self, RbTROSXAuth, pRbTROSXAuth);
|
88
|
+
|
89
|
+
if( pRbTROSXAuth->rbAuth == Qfalse )
|
90
|
+
{
|
91
|
+
AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL, 0};
|
92
|
+
AuthorizationRights myRights = {1, &myItems};
|
93
|
+
AuthorizationFlags myFlags =
|
94
|
+
kAuthorizationFlagDefaults |
|
95
|
+
kAuthorizationFlagInteractionAllowed |
|
96
|
+
kAuthorizationFlagPreAuthorize |
|
97
|
+
kAuthorizationFlagExtendRights;
|
98
|
+
|
99
|
+
pRbTROSXAuth->myStatus = AuthorizationCopyRights(
|
100
|
+
pRbTROSXAuth->myAuthorizationRef, &myRights, NULL, myFlags, NULL );
|
101
|
+
}
|
102
|
+
if( pRbTROSXAuth->myStatus == errAuthorizationSuccess ) {
|
103
|
+
pRbTROSXAuth->rbAuth = Qtrue;
|
104
|
+
}
|
105
|
+
|
106
|
+
return INT2NUM(pRbTROSXAuth->myStatus);
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
* Check if autorizations are set
|
111
|
+
*/
|
112
|
+
VALUE rosxauth_auth_q(VALUE self) {
|
113
|
+
RbTROSXAuth *pRbTROSXAuth;
|
114
|
+
Data_Get_Struct(self, RbTROSXAuth, pRbTROSXAuth);
|
115
|
+
|
116
|
+
return( pRbTROSXAuth->rbAuth );
|
117
|
+
}
|
118
|
+
|
119
|
+
/*
|
120
|
+
* Runs an executable tool with root privileges.
|
121
|
+
*
|
122
|
+
* f = hh.exec( "/bin/ls", ["-l", "-a"] )
|
123
|
+
* if f.nil?
|
124
|
+
* puts "i said NO !!!"
|
125
|
+
* else
|
126
|
+
* IO.for_fd( f ).each do | g |
|
127
|
+
* g.each_line { | l | puts l }
|
128
|
+
* end
|
129
|
+
* end
|
130
|
+
*
|
131
|
+
* Return a file descriptor.
|
132
|
+
*/
|
133
|
+
VALUE rosxauth_exec( VALUE self, VALUE tool, VALUE args ) {
|
134
|
+
char *cTool = STR2CSTR(tool);
|
135
|
+
char **cArgs = NULL;
|
136
|
+
FILE *execPipe = NULL;
|
137
|
+
int i, argsLen;
|
138
|
+
|
139
|
+
RbTROSXAuth *pRbTROSXAuth;
|
140
|
+
Data_Get_Struct(self, RbTROSXAuth, pRbTROSXAuth);
|
141
|
+
|
142
|
+
// Auth if needed
|
143
|
+
if( pRbTROSXAuth->rbAuth == Qfalse ) {
|
144
|
+
VALUE r = rosxauth_auth( self );
|
145
|
+
if( pRbTROSXAuth->rbAuth == Qfalse ) {
|
146
|
+
return( Qnil );
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
// Make args array
|
151
|
+
switch(TYPE( args ) ) {
|
152
|
+
case T_NIL:
|
153
|
+
cArgs = NULL;
|
154
|
+
break;
|
155
|
+
|
156
|
+
case T_STRING:
|
157
|
+
cArgs = (char**)malloc(sizeof(char*)*2);
|
158
|
+
cArgs[0] = STR2CSTR(args);
|
159
|
+
cArgs[1] = NULL;
|
160
|
+
break;
|
161
|
+
|
162
|
+
case T_ARRAY:
|
163
|
+
argsLen = RARRAY(args)->len;
|
164
|
+
cArgs = (char**)malloc(sizeof(char*)*(argsLen + 1));
|
165
|
+
for( i = 0; i < argsLen; i++ ) {
|
166
|
+
switch(TYPE(RARRAY(args)->ptr[i])) {
|
167
|
+
case T_STRING:
|
168
|
+
cArgs[i] = STR2CSTR(RARRAY(args)->ptr[i]);
|
169
|
+
break;
|
170
|
+
case T_FLOAT:
|
171
|
+
cArgs[i] = (char*)malloc(sizeof(char)*255);
|
172
|
+
sprintf( cArgs[i], "%f", NUM2DBL(RARRAY(args)->ptr[i]) );
|
173
|
+
break;
|
174
|
+
case T_FIXNUM:
|
175
|
+
case T_BIGNUM:
|
176
|
+
cArgs[i] = (char*)malloc(sizeof(char)*255);
|
177
|
+
sprintf( cArgs[i], "%d", NUM2INT(RARRAY(args)->ptr[i]) );
|
178
|
+
break;
|
179
|
+
default:
|
180
|
+
rb_raise( eROSXAuthError, "Parameter type not allowed !" );
|
181
|
+
break;
|
182
|
+
}
|
183
|
+
}
|
184
|
+
cArgs[argsLen] = NULL;
|
185
|
+
break;
|
186
|
+
|
187
|
+
default:
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
|
191
|
+
// Execute !
|
192
|
+
pRbTROSXAuth->myStatus = AuthorizationExecuteWithPrivileges(
|
193
|
+
pRbTROSXAuth->myAuthorizationRef,
|
194
|
+
cTool,
|
195
|
+
kAuthorizationFlagDefaults,
|
196
|
+
cArgs,
|
197
|
+
&execPipe);
|
198
|
+
|
199
|
+
return INT2FIX(fileno(execPipe));
|
200
|
+
}
|
data/ext/rosxauth.h
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <Security/Authorization.h>
|
4
|
+
#include <Security/AuthorizationTags.h>
|
5
|
+
|
6
|
+
typedef struct RbTROSXAuth {
|
7
|
+
VALUE rbAuth;
|
8
|
+
OSStatus myStatus;
|
9
|
+
AuthorizationRef myAuthorizationRef;
|
10
|
+
} RbTROSXAuth;
|
11
|
+
|
12
|
+
// Prototype for the initialization method
|
13
|
+
void Init_rosxauth();
|
14
|
+
VALUE cROSXAuth;
|
15
|
+
VALUE eROSXAuthError;
|
16
|
+
|
17
|
+
void rosxauth_free(RbTROSXAuth *);
|
18
|
+
void rosxauth_mark(RbTROSXAuth *);
|
19
|
+
VALUE rosxauth_new(VALUE);
|
20
|
+
|
21
|
+
VALUE rosxauth_status(VALUE);
|
22
|
+
VALUE rosxauth_auth(VALUE);
|
23
|
+
VALUE rosxauth_auth_q(VALUE);
|
24
|
+
VALUE rosxauth_exec( VALUE, VALUE, VALUE );
|
data/test/test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require '../lib/rosxauth'
|
2
|
+
|
3
|
+
h = ROSXAuth.new()
|
4
|
+
if( h.auth == ROSXAuth::ErrAuthorizationSuccess )
|
5
|
+
puts "Success !"
|
6
|
+
else
|
7
|
+
puts "No, you can continue !"
|
8
|
+
end
|
9
|
+
|
10
|
+
if h.auth?
|
11
|
+
puts "C'est tout bon !!!"
|
12
|
+
end
|
13
|
+
|
14
|
+
f = h.exec( "/bin/ls", "-l" )
|
15
|
+
if f.nil?
|
16
|
+
puts "i said NO !!!"
|
17
|
+
else
|
18
|
+
IO.for_fd( f ).each do | g |
|
19
|
+
g.each_line { | l | puts l }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
f = h.exec( "/usr/bin/touch", "pipo.txt" )
|
24
|
+
if f.nil?
|
25
|
+
puts "i said NO !!!"
|
26
|
+
else
|
27
|
+
IO.for_fd( f ).each do | g |
|
28
|
+
g.each_line { | l | puts l }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
hh = ROSXAuth.new()
|
33
|
+
|
34
|
+
f = hh.exec( "/bin/ls", ["-l", "-a"] )
|
35
|
+
if f.nil?
|
36
|
+
puts "i said NO !!!"
|
37
|
+
else
|
38
|
+
IO.for_fd( f ).each do | g |
|
39
|
+
g.each_line { | l | puts l }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
f = hh.exec( "/bin/ls", [self, "-l"] )
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rosxauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregoire Lejeune
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-22 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby/XSLT is a simple class used to give root execution privileges on MacOSX
|
17
|
+
email: gregoire.lejeune@free.fr
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- ChangeLog
|
25
|
+
- COPYING
|
26
|
+
- AUTHORS
|
27
|
+
files:
|
28
|
+
- ChangeLog
|
29
|
+
- COPYING
|
30
|
+
- README.rdoc
|
31
|
+
- AUTHORS
|
32
|
+
- test/test.rb
|
33
|
+
- lib/rosxauth/version.rb
|
34
|
+
- ext/rosxauth.h
|
35
|
+
- ext/rosxauth.c
|
36
|
+
- ext/extconf.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/glejeune/ROSXAuth
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --title
|
44
|
+
- ROSXAuth
|
45
|
+
- --main
|
46
|
+
- README.rdoc
|
47
|
+
- --line-numbers
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: rosxauth
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: A Ruby class to give root execution privileges on MacOSX
|
69
|
+
test_files: []
|
70
|
+
|