This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Valor, meet Discretion
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
I've been working on methods for adding, configuring, and deleting users and groups as part of the Admin package. This is fairly trivial on the Win32 platform, where the Win32 API is kind enough to provide me with some handy methods for performing such operations.
Unix, on the other hand, is very unfriendly in this regard. The only functions I could find to help me were putpwent() and putspent(), and these are "discouraged" because it's a multi-step process to add a passwd entry, and it only works for local entries (i.e. no NIS). You have to open the file, lock the, write the entry to the passwd file, write the entry to the shadow file, unlock the passwd file, and then close the file. This is to say nothing of handling password encryption, or figuring out if and where shadow password files exist on other platforms. Oh, and there are no methods for configuring or deleting users or groups.
So, I have two choices. The first is to write my own functions for adding, deleting and configuring users. Ick. That could take a while, and would require lots of thorough testing. I don't want to mess up someone's passwd file, you know. The second choice, and the one I'm heavily leaning towards now, is to simply use a system call, e.g. system("useradd -blah blah").
I'll have to see just how "standard" the options to useradd, etc, are across different flavors of Unix, though.