[Mono-devel-list] User account information through Mono

Jonathan Stowe jns at gellyfish.com
Thu Aug 26 06:47:00 EDT 2004


On Thu, 2004-08-26 at 07:28, Hemanth Yamijala wrote:
> Hi,
> 
> Are there any Mono C# APIs that provide a similar behavior 
> to the getpw* family of functions on Linux / Posix - These 
> parse information in the /etc/passwd file and return it in the 
> form of some structures.
> 
> Didn't seem to find any such in the Mono.Posix branch or the
> in general the Mono libraries link in the documentation.
> 

Funny you may say that.  I have been working on just such a thing. 
Pending a proper release (you know with like documentation, tests and
instructions and so forth) you can find the source code here:

    http://www.integration-house.com/files/Linux.User.tar.gz

it simply requires you to run 'make' - however, despite the fact that it
is fully managed code it requires a C compiler to generate some stuff
from the C header files so you may need to adjust the C compiler in the
Makefile.

Currently the only documentation is in the source.

Example of using the Password class:

using Linux.User;
                                                                                
class Test
{
   public static void Main()
   {
      Password pw = new Password();
                                                                                
      PasswordEntry pwent;
                                                                                
      while ((pwent = pw.GetPWEnt()) != null )
      {
         System.Console.WriteLine(pwent.Name);
      }
                                                                                
   }
                                                                                
}

Example of using the Utmp class:

using Linux.User;
using System;
                                                                                
class Test
{
   public static void Main()
   {
      Utmp utmp = new Utmp();
                                                                                
      foreach (Utent utent in utmp.Entries )
      {
         Console.WriteLine(utent.ut_user);
      }
   }
}


Example of using LastLog class

using Linux.User;
                                                                                
class Test
{
   public static void Main()
   {
      LastLog ll = new LastLog();
                                                                                
      LastLogEntry pwent;
                                                                                
      pwent = ll.GetLlName("root");
      System.Console.WriteLine(pwent.Time);
   }
                                                                                
}




Complaints, suggestions, patches etc are welcome.

/J\




More information about the Mono-devel-list mailing list