From djberg96 at gmail.com Mon Mar 2 00:54:08 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 1 Mar 2009 22:54:08 -0700 Subject: [Win32utils-devel] Getting a list of groups for a given user Message-ID: <6037b70c0903012154y5aa86702n4ef5ecf72a6a1542@mail.gmail.com> Hi, How does this look for finding a list of groups for a particular user? This is for the sys-admin library. Assume "self.name" is pretty much the same thing as Etc.getlogin would return. # admin.rb Class User def groups(domain=nil) host = Socket.gethostname cs = "winmgmts:{impersonationLevel=impersonate}!" cs << "//#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err end if domain query = " select * from Win32_GroupUser where partcomponent = " query << "\"Win32_UserAccount.Domain='#{domain.upcase}',Name='#{self.name}'\"" else query = " select * from Win32_GroupUser where partcomponent = " query << "\"Win32_UserAccount.Domain='#{host.upcase}',Name='#{self.name}'\"" end array = [] wmi.execquery(query).each{ |groupuser| array << groupuser.GroupComponent.split('=').last.tr('"', '') } array end end Regards, Dan From Daniel.Berger at qwest.com Tue Mar 3 15:50:27 2009 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Tue, 3 Mar 2009 14:50:27 -0600 Subject: [Win32utils-devel] Getting a list of groups for a given user In-Reply-To: <6037b70c0903012154y5aa86702n4ef5ecf72a6a1542@mail.gmail.com> References: <6037b70c0903012154y5aa86702n4ef5ecf72a6a1542@mail.gmail.com> Message-ID: > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Daniel Berger > Sent: Sunday, March 01, 2009 10:54 PM > To: Development and ideas for win32utils projects > Subject: [Win32utils-devel] Getting a list of groups for a given user > > Hi, > > How does this look for finding a list of groups for a particular user? > > This is for the sys-admin library. Assume "self.name" is > pretty much the same thing as Etc.getlogin would return. > > # admin.rb > Class User > def groups(domain=nil) > host = Socket.gethostname > cs = "winmgmts:{impersonationLevel=impersonate}!" > cs << "//#{host}/root/cimv2" > > begin > wmi = WIN32OLE.connect(cs) > rescue WIN32OLERuntimeError => err > raise Error, err > end > > if domain > query = " select * from Win32_GroupUser where > partcomponent = " > query << > "\"Win32_UserAccount.Domain='#{domain.upcase}',Name='#{self.name}'\"" > else > query = " select * from Win32_GroupUser where > partcomponent = " > query << > "\"Win32_UserAccount.Domain='#{host.upcase}',Name='#{self.name}'\"" > end > > array = [] > > wmi.execquery(query).each{ |groupuser| > array << > groupuser.GroupComponent.split('=').last.tr('"', '') > } > > array > end > end Nevermind this. It was easier to use the IADsUser interface: adsi = WIN32OLE.connect("WinNT://some_domain/some_user") adsi.groups.each{ |g| p g.name } Regards, Dan From Daniel.Berger at qwest.com Wed Mar 4 13:57:01 2009 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Wed, 4 Mar 2009 12:57:01 -0600 Subject: [Win32utils-devel] Checking privileges for adding, configuring or deleting users Message-ID: Hi all, Windows XP Pro Ruby 1.8.6-p114 How would I go about checking to see if I have privileges to add, configure or delete users? Or is it just a matter of checking for admin privileges? I ask because I have some tests for the sys-admin library I'd like to skip if the current process doesn't have the proper privileges. Regards, Dan From phasis at gmail.com Wed Mar 4 23:54:08 2009 From: phasis at gmail.com (Heesob Park) Date: Thu, 5 Mar 2009 13:54:08 +0900 Subject: [Win32utils-devel] Checking privileges for adding, configuring or deleting users In-Reply-To: References: Message-ID: Hi, 2009/3/5 Berger, Daniel : > Hi all, > > Windows XP Pro > Ruby 1.8.6-p114 > > How would I go about checking to see if I have privileges to add, configure or delete users? Or is it just a matter of checking for admin privileges? > > I ask because I have some tests for the sys-admin library I'd like to skip if the current process doesn't have the proper privileges. > Something like this would be possible: require 'windows/api' include Windows POLICY_CREATE_ACCOUNT = 0x00000010 POLICY_LOOKUP_NAMES = 0x00000800 ERROR_ACCESS_DENIED = 5 LsaOpenPolicy = API.new('LsaOpenPolicy', 'PPLP', 'L', 'advapi32') LsaClose = API.new('LsaClose', 'L', 'L', 'advapi32') LsaNtStatusToWinError = API.new('LsaNtStatusToWinError', 'L', 'L', 'advapi32') attr = 0.chr * 24 handle = 0.chr * 4 status = LsaOpenPolicy.call(nil,attr,POLICY_CREATE_ACCOUNT|POLICY_LOOKUP_NAMES,handle) if status != 0 && LsaNtStatusToWinError.call(status)==ERROR_ACCESS_DENIED puts "insufficient privilege" else LsaClose.call(handle.unpack('L').first) end Regards, Park Heesob From djberg96 at gmail.com Thu Mar 5 20:00:01 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Thu, 05 Mar 2009 18:00:01 -0700 Subject: [Win32utils-devel] Checking privileges for adding, configuring or deleting users In-Reply-To: References: Message-ID: <49B07591.3010703@gmail.com> Heesob Park wrote: > Hi, > > 2009/3/5 Berger, Daniel : >> Hi all, >> >> Windows XP Pro >> Ruby 1.8.6-p114 >> >> How would I go about checking to see if I have privileges to add, configure or delete users? Or is it just a matter of checking for admin privileges? >> >> I ask because I have some tests for the sys-admin library I'd like to skip if the current process doesn't have the proper privileges. >> > Something like this would be possible: > > require 'windows/api' > include Windows > > POLICY_CREATE_ACCOUNT = 0x00000010 > POLICY_LOOKUP_NAMES = 0x00000800 > ERROR_ACCESS_DENIED = 5 > > LsaOpenPolicy = API.new('LsaOpenPolicy', 'PPLP', 'L', 'advapi32') > LsaClose = API.new('LsaClose', 'L', 'L', 'advapi32') > LsaNtStatusToWinError = API.new('LsaNtStatusToWinError', 'L', 'L', 'advapi32') > > attr = 0.chr * 24 > handle = 0.chr * 4 > status = LsaOpenPolicy.call(nil,attr,POLICY_CREATE_ACCOUNT|POLICY_LOOKUP_NAMES,handle) > if status != 0 && LsaNtStatusToWinError.call(status)==ERROR_ACCESS_DENIED > puts "insufficient privilege" > else > LsaClose.call(handle.unpack('L').first) > end Nice, thanks! Dan From djberg96 at gmail.com Thu Mar 5 20:01:53 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Thu, 05 Mar 2009 18:01:53 -0700 Subject: [Win32utils-devel] [Fwd: open3.c patch] Message-ID: <49B07601.7020509@gmail.com> This look good? Dan -------------- next part -------------- An embedded message was scrubbed... From: Ross Bunker Subject: open3.c patch Date: Thu, 5 Mar 2009 14:19:00 -0500 (EST) Size: 1966 URL: From phasis at gmail.com Thu Mar 5 20:39:07 2009 From: phasis at gmail.com (Heesob Park) Date: Fri, 6 Mar 2009 10:39:07 +0900 Subject: [Win32utils-devel] [Fwd: open3.c patch] In-Reply-To: <49B07601.7020509@gmail.com> References: <49B07601.7020509@gmail.com> Message-ID: 2009/3/6 Daniel Berger : > This look good? > > Dan > > Hi Daniel, > We're using win32/open. ?We started seeing apparently bogus exit codes with > 0.2.6, so we updated to 0.2.8. ?The fixes sounded right on the money, but > the problem didn't go away. ?I debugged a bit further and saw that we were > getting an invalid handle exception. ?Looks like one more tweak is needed to > get the exit code handling exactly right. > > --- open3.c.orig ? ? ? ?Thu Mar 05 11:02:16 2009 > +++ open3.c ? ? Thu Mar 05 11:05:33 2009 > @@ -281,9 +281,9 @@ > > ? ?if(pid_handle != NULL){ > ? ? ? GetExitCodeProcess(pid_handle, &status); > - ? ? ?CloseHandle(pid_handle); > > ? ? ? if(status != STILL_ACTIVE){ > + ? ? ? ? CloseHandle(pid_handle); > ? ? ? ? ?pid_handle = NULL; > ? ? ? ? ?win32_set_last_status(status, file->pid); > ? ? ? } > > thanks for all the great code. > :)ross > That looks good. Regards, Park Heesob From noreply at rubyforge.org Mon Mar 30 13:34:48 2009 From: noreply at rubyforge.org (noreply at rubyforge.org) Date: Mon, 30 Mar 2009 13:34:48 -0400 (EDT) Subject: [Win32utils-devel] [ win32utils-Support Requests-24279 ] Windows 7 x64 - building a win32-api gem on windows Message-ID: <20090330173449.0B99C197857A@rubyforge.org> Support Requests item #24279, was opened at 2009-03-03 06:51 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=412&aid=24279&group_id=85 Category: win32-api Group: v1.0 (example) Status: Open Resolution: None Priority: 3 Submitted By: Nobody (None) Assigned to: Nobody (None) Summary: Windows 7 x64 - building a win32-api gem on windows Initial Comment: Hi Guys, I have been trying to install win32-api 1.4.0 gem on windows 7 x64 but no success. When i install x86 version, require 'win32/api' gives me following error: LoadError: 193: %1 is not a valid Win32 application. - c:/ruby/lib/ruby/gems/1.9.1/gems/win32-api-1.4.0-x86-mswin32-60/lib/win32/api.so from (irb):1:in `require' from (irb):1 from c:/ruby/bin/irb.bat:20:in `
' My ruby: ruby 1.9.1p0 (2009-01-30 revision 21907) [x64-mswin64_80] My gems: 1.3.1 I have VS2008 installed and even managed to create a makefile but it complains about following: C:\>gem install win32-api Building native extensions. This could take a while... ERROR: Error installing win32-api: ERROR: Failed to build gem native extension. c:/ruby/bin/ruby.exe extconf.rb install win32-api checking for strncpy_s()... yes creating Makefile nmake Microsoft (R) Program Maintenance Utility Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. c:\ruby\bin\ruby -e "puts 'EXPORTS', 'Init_api'" > api-x64-mswin64_80.def cl -nologo -I. -Ic:/ruby/include/ruby-1.9.1/x64-mswin64_80 -Ic:/ruby/include/ruby-1.9.1/ruby/backward -Ic:/ruby/include/ruby-1.9.1 -Iwin32 -MD -Zi -O2b 2xty- -Zm600 -DHAVE_STRNCPY_S -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -Foapi.obj -c -Tcwin32/api.c api.c cl -nologo -LD -Feapi.so api.obj msvcr80-ruby191.lib oldnames.lib user32.lib advapi32.lib shell32.lib ws2_32.lib -link -incremental:no -debug -opt:re f -opt:icf -dll -libpath:"." -libpath:"c:/ruby/lib" -implib:api-x64-mswin64_80.lib -pdb:api-x64-mswin64_80.pdb -def:api-x64-mswin64_80.def Creating library api-x64-mswin64_80.lib and object api-x64-mswin64_80.exp api.obj : error LNK2019: unresolved external symbol _rb_num2long referenced in function _NUM2LONG api.obj : error LNK2019: unresolved external symbol _rb_int2big referenced in function _LONG2NUM api.obj : error LNK2019: unresolved external symbol _rb_uint2big referenced in function _ULONG2NUM api.obj : error LNK2019: unresolved external symbol _rb_data_object_alloc referenced in function _api_allocate api.obj : error LNK2019: unresolved external symbol _rb_raise referenced in function _StringError api.obj : error LNK2019: unresolved external symbol _rb_iv_set referenced in function _callback_init api.obj : error LNK2019: unresolved external symbol _rb_str_new_cstr referenced in function _callback_init api.obj : error LNK2019: unresolved external symbol _rb_scan_args referenced in function _callback_init api.obj : error LNK2019: unresolved external symbol _rb_string_value_ptr referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_str_cat referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_str_new_shared referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_check_safe_obj referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_string_value referenced in function _api_init api.obj : error LNK2001: unresolved external symbol __imp__rb_eArgError api.obj : error LNK2019: unresolved external symbol _rb_ary_push referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_ary_new referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_str_split referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_respond_to referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_intern referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_check_type referenced in function _api_init api.obj : error LNK2019: unresolved external symbol _rb_str_modify referenced in function _CallbackFunction api.obj : error LNK2019: unresolved external symbol _rb_num2ulong referenced in function _CallbackFunction api.obj : error LNK2019: unresolved external symbol _rb_funcall2 referenced in function _CallbackFunction api.obj : error LNK2019: unresolved external symbol _rb_iv_get referenced in function _CallbackFunction api.obj : error LNK2019: unresolved external symbol _rb_str_new referenced in function _api_call api.obj : error LNK2019: unresolved external symbol _rb_define_const referenced in function _Init_api api.obj : error LNK2019: unresolved external symbol _rb_define_attr referenced in function _Init_api api.obj : error LNK2019: unresolved external symbol _rb_define_method referenced in function _Init_api api.obj : error LNK2019: unresolved external symbol _rb_define_alloc_func referenced in function _Init_api api.obj : error LNK2001: unresolved external symbol __imp__rb_eRuntimeError api.obj : error LNK2019: unresolved external symbol _rb_define_class_under referenced in function _Init_api api.obj : error LNK2001: unresolved external symbol __imp__rb_cObject api.obj : error LNK2019: unresolved external symbol _rb_define_module referenced in function _Init_api api.so : fatal error LNK1120: 33 unresolved externals NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.EXE"' : return code '0x2' Stop. Gem files will remain installed in c:/ruby/lib/ruby/gems/1.9.1/gems/win32-api-1.4.0 for inspection. Results logged to c:/ruby/lib/ruby/gems/1.9.1/gems/win32-api-1.4.0/ext/gem_make.out Does anyone have any idea about building gem on windows? Or maybe you have precompiled api.so on your x64 system. I would appreciate your help. ---------------------------------------------------------------------- >Comment By: Daniel Berger (djberg96) Date: 2009-03-30 10:34 Message: Wow, I'm not sure at this point. I've built it without issue on x64 Vista, but I simply don't have access to Windows 7 to comment further. I'm afraid we really can't support Windows 7 until it's officially released. Regards, Dan ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=412&aid=24279&group_id=85