# Strange Segfault

**URL:** <https://www.ruby-forum.com/t/strange-segfault/109368>\
**Category:** Ruby\
**Created:** [July 13, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368 "2007-07-13T20:04:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 13, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368/1 "2007-07-13T20:04:21Z")

</div>

I have an interesting problem. I have a script that I wish to use to  
check  
a database and then map drives based on who is logging on and the info  
in  
the database.

When I run the script on any of the machines in the computer lab it  
segfaults. When I copy the exact same code that is in the script into  
an  
irb session and run it I don’t have any trouble. I can run the script  
proper on my office workstation.

Does anyone have any idea what could be causing this?

I’m running ruby 1.8.6 on all the machines in question.

Here is the script:

require ‘Win32API’  
require ‘xmlrpc/client’

class User  
def lookup  
user = “0” \* 20

```
getUserName = Win32API.new("advapi32", "GetUserName", 'P', "V")

getUserName.call(user)

return user
end

def account_created?(login)
    server = XMLRPC::Client.new2('http://localhost:3003/user/api')

    result = server.call('Check', login)

    if result == 0
      return false
    else
        return true
    end
end

def map_drives(login)
    system("net use x: /delete /y")
    system("net use l: /delete /y")
    system("net use x: //cad1/#{login}")
    system("net use l: //cad1/shared")
end

```

end

user = User.new

username = user.lookup

if user.account\_created?(username)  
user.map\_drives(username)  
end

–  
“Hey brother christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 13, 2007, 9:11pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368/2 "2007-07-13T21:11:33Z")

</div>

On Jul 13, 12:03 pm, “Glen H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> result = server.call('Check', login)
> system("net use l: /delete /y")
> user.map_drives(username)
> 
> ```
> 
> end

What version of Windows are you on? Is there a backtrace you could  
show us? That would help us determine whether or not it’s the system  
calls or something else.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 13, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368/3 "2007-07-13T22:42:48Z")

</div>

On 7/13/07, Glen H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > the database.
> > > 
> > > ```
> > > result = server.call('Check', login)
> > > system("net use l: /delete /y")
> > > user.map_drives(username)
> > > 
> > > ```
> 
> speak  
> so loud, I can’t hear a word you’re saying."
> 
> -Greg Graffin (Bad Religion)

Okay for reasons I’m not sure of right now and don’t have time to  
investigate changing the server.call to server.call2 fixed the problem.

–  
“Hey brother christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 13, 2007, 11:11pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368/4 "2007-07-13T23:11:51Z")

</div>

On Jul 13, 2:39 pm, “Glen H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Okay for reasons I’m not sure of right now and don’t have time to  
> investigate changing the server.call to server.call2 fixed the problem.

For some reason my last post never made it…

In short, your declaration of GetUserName is wrong - it takes 2  
parameters, not 1, and you aren’t checking for failure. As it stands  
now it looks like “login” will always be an empty string.

Save yourself some time and use Admin.get\_login from the sys-admin  
package, which you can install via rubygems.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 13, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368/5 "2007-07-13T22:15:45Z")

</div>

On 7/13/07, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > When I run the script on any of the machines in the computer lab it
> > 
> > ```
> > return false
> > end
> > 
> > ```
> 
> What version of Windows are you on? Is there a backtrace you could  
> show us? That would help us determine whether or not it’s the system  
> calls or something else.
> 
> Regards,
> 
> Dan
> 
> All the machines involved are running XP Pro.

This is the best I can get out of it:

c:\ruby\lib\ruby\1.8\xmlrpc\client.rb:414:in ‘call’  
C:\Startup\map.rb:24:in ‘account\_created?’  
C:\Startup\map.rb:50

–  
“Hey brother christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 14, 2007, 12:24am UTC](https://www.ruby-forum.com/t/strange-segfault/109368/6 "2007-07-14T00:24:58Z")

</div>

On 7/13/07, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> For some reason my last post never made it…  
> Dan

Thanks for the info I wouldn’t have caught it otherwise as it actually  
gives  
me the proper username. I will look into the sys-admin package.

–  
“Hey brother christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 16, 2007, 4:08pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368/7 "2007-07-16T16:08:25Z")

</div>

Daniel,

sys-admin looks like it will do what I need however the link (  
[http://tinyurl.com/cjkzl](http://tinyurl.com/cjkzl)) in the documentation on rubyforge is broken.  
MSDN  
just throws a 404 page.

I’m trying to find the options for the config\_global\_group method.

Thanks.

On 7/13/07, Glen H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> –  
> “Hey brother christian with your high and mighty errand, Your actions  
> speak  
> so loud, I can’t hear a word you’re saying.”
> 
> -Greg Graffin (Bad Religion)

–  
“Hey brother christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 16, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368/8 "2007-07-16T22:25:11Z")

</div>

Thanks Dan,

That looks like it should do everything I need. Annoying that  
GetUserName  
returns the name of the account that owns the process not the actual  
account  
that is logged-in locally, so much for running it as a service.

-Glen

On 7/16/07, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Dan

–  
“Hey brother christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [July 16, 2007, 6:08pm UTC](https://www.ruby-forum.com/t/strange-segfault/109368/9 "2007-07-16T18:08:39Z")

</div>

On Jul 16, 8:04 am, “Glen H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Daniel,
> 
> sys-admin looks like it will do what I need however the link ([http://tinyurl.com/cjkzl](http://tinyurl.com/cjkzl)) in the documentation on rubyforge is broken. MSDN  
> just throws a 404 page.

That’s because MS insists on moving its documentation every 6 months  
in order to make it more Ajaxy and less functional. But I digress…

Try [IADsUser (iads.h) - Win32 apps | Microsoft Learn](http://msdn2.microsoft.com/en-us/library/aa746340.aspx) and look at  
the “properties” section.

For future searchers if that link is dead just search [msdn.com](http://msdn.com) on  
“IADsGroup” or “adsi + group”.

Regards,

Dan
