[ANN] sys-win32etc 0.0.2

D

Daniel Berger

Hi all,

I'm happy to announce the release of sys-win32etc 0.0.2. This is an
ALPHA release.

What is it? This is my attempt to port the Etc module to Win32 systems
(well, NT, 2000 and XP anyway). If all goes well, I hope to get Matz to
include this as part of core Ruby.

HELP WANTED! See "Where I need help" below.

Changes since 0.0.1
===================
- Replaced most calls to NetQueryDisplayInformation() with less unicode
friendly, but easier, method calls.
- The group() method now returns local group info as well (only global
groups
were returned before).
- All methods except getlogin() now accept a server name as an optional
argument. If provided, lookups are done against that server instead
of the
local machine.
- Calling group() or passwd() in non-block form now returns nil, as it
does
on *nix.
- Test suite and documentation changes to reflect changes in code.


Synopsis
========
require "win32etc"

puts "Login: " + Win32Etc.getlogin

p Win32Etc.getpwnam("Guest","\\some_server")
p Win32Etc.getpwuid(512)
p Win32Etc.getgrnam("Guests")
p Win32Etc.getgrgid(500,"\\some_server")

Win32Etc.passwd{ |s|
p s
}

Win32Etc.group("\\some_server"){ |g|
p g
}

Where I need help
=================
Memory leaks. Don't panic - these are only an issue if you do repeated
calls in a tight loop of some kind. Single calls are harmless. I don't
know where they're coming from or what I can do about it.

Remote server testing - I don't have a machine to test against for
calling a method against a remote server instead of the local machine.
Testing much appreciated on that front.

Insight into why I should or shouldn't use NetQueryDisplayInformation()
instead of NetGroupEnum(), etc. Hopefully, something beyond, "Because
the MSDN site says so".

For more information
====================
For general info on porting *nix to Windows see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnucmg/html/ucmgch09.asp

See http://msdn.microsoft.com/library/default.asp to search for API
info.

Regards,

Dan
 
S

Shashank Date

Daniel Berger said:
- Replaced most calls to NetQueryDisplayInformation() with less unicode
friendly, but easier, method calls.

But I think this may be problematic because win32 API (e.g. NetUserEnum())
expects unicode.
- All methods except getlogin() now accept a server name as an optional
argument. If provided, lookups are done against that server instead
of the local machine.

This part did not work for me.
Synopsis
========
require "win32etc"

puts "Login: " + Win32Etc.getlogin

p Win32Etc.getpwnam("Guest","\\some_server")
^^^^^^^^^^^^
I think this should be "\\\\someserver"
Remote server testing - I don't have a machine to test against for
calling a method against a remote server instead of the local machine.
Testing much appreciated on that front.

Like I said earlier, this did not work for me. I guess this is because of
lines such as

szServer = (LPCWSTR)STR2CSTR(server);

in your code. I think STR2CSTR returns regular C strings (char *) not
unicode (wchar_t *) strings. Is there a way to convert regular strings to
unicode in Ruby ?

Let me know if you need to see my C code ;-)
Insight into why I should or shouldn't use NetQueryDisplayInformation()
instead of NetGroupEnum(), etc. Hopefully, something beyond, "Because

Sorry, I have no idea why ... can't help you there.

By the way the link in RAA to your download is wrong, it should be:

http://prdownloads.sourceforge.net/ruby-sysutils/sys-win32etc-0.0.2.zip?download

Hope that helps.
-- shanko
 
S

Shashank Date

Shashank Date said:
Like I said earlier, this did not work for me. I guess this is because of
lines such as

szServer = (LPCWSTR)STR2CSTR(server);

in your code. I think STR2CSTR returns regular C strings (char *) not
unicode (wchar_t *) strings. Is there a way to convert regular strings to
unicode in Ruby ?

Ok, I changed your code
from :

if(server != Qnil){
szServer = (LPCWSTR)STR2CSTR(server);
}
else{
szServer = NULL;
}

to
if(server != Qnil){
wchar_t wszTemp[MAX_PATH];
mbstowcs(wszTemp, STR2CSTR(server), MAX_PATH);
szServer = (LPCWSTR)wszTemp;
}
else{
szServer = NULL;
}

And now it is working fine except this line:

p Win32Etc.getgrgid(500,"\\\\MYMACHINE")

It gives error as follows:

C:/atest/tst_win_etc.rb:10:in `getgrgid': can't find group for 500
(ArgumentError)
from C:/atest/tst_win_etc.rb:10

What's with group 500 ? I tried 500, 501, 510, etc but to no vail.

HTH,
-- shanko
 
S

Shashank Date

Shashank Date said:
And now it is working fine except this line:

p Win32Etc.getgrgid(500,"\\\\MYMACHINE")

It gives error as follows:

C:/atest/tst_win_etc.rb:10:in `getgrgid': can't find group for 500
(ArgumentError)
from C:/atest/tst_win_etc.rb:10

What's with group 500 ? I tried 500, 501, 510, etc but to no vail.

Sorry ! Posted too early ... should have tried 513 before giving up ;-)

Now *everything* is working great !

Good work, Daniel.
Thanks a lot.
-- shanko

PS> BTW, are you the same person who has interfaced VC++ to
Lego mindstorms? http://www.kyb.tuebingen.mpg.de/~berger

-- shanko
 
S

Shashank Date

Daniel Berger said:
Hmm...'\\' should work with single quotes. Please try and let me
know. If so, I'll update the docs.

Did not work with single quotes either. Had to use double-backslash twice.
Thank you very much for the feedback. Any idea on the memory leaks?
To see what I mean, try this bit of code and pull up the Task Manager
to watch the memory usage:

while 1
Win32Etc.group{ |g|
p g
}
sleep 3
end

Not that you would do this in real code, but it demonstrates the
problem.

Yes, I could recreate the problem but have not figured a way to avoid
it. Will take a look at it over the wekk-end (if possible).

-- shanko
 
D

Daniel Berger

Park Heesob said:
The memory leak is due to memory allocation of struct like these

VALUE gstruct = rb_struct_new(Group);

rb_struct_aset(gstruct,INT2NUM(0),rb_str_new2(dest));


A simple and stupid solution is replace

if(rb_block_given_p()){
rb_yield(gstruct);
}
with
if(rb_block_given_p()){
rb_ensure(rb_yield,gstruct,obj_free,gstruct);
}

and define obj_free like this

static VALUE obj_free(VALUE obj)
{
rb_gc();
return Qnil;
}

That seems to solve the problem for the group() method, but I still
get leaks with the passwd() method with this approach. Any ideas?

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top