Class: Sys::User

Inherits:
Object
  • Object
show all
Defined in:
ext/sys/admin.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#newObject #new {|user| ... } ⇒ Object

Creates and returns a User object, which encapsulates the information typically found within an /etc/passwd entry, i.e. a struct passwd.

If a block is provided, yields the object back to the block.

Overloads:

  • #new {|user| ... } ⇒ Object

    Yields:

    • (user)


24
25
26
27
28
29
# File 'ext/sys/admin.c', line 24

static VALUE user_init(VALUE self){
   if(rb_block_given_p())
      rb_yield(self);

   return self;
}

Instance Attribute Details

#access_classObject

The user’s access class

#ageObject

Used in the past for password aging. Deprecated in favor of /etc/shadow

#changeObject

Next date a password change will be needed

#commentObject

Another comment field. Rarely used.

#dirObject

The absolute pathname of the user’s home directory

#expireObject

Account expiration date

#gecosObject

A comment field. Rarely used.

#gidObject

The user’s primary group ID

#login_deviceObject (readonly)

The name of the terminal device the user last logged on with

#login_hostObject (readonly)

The hostname from which the user last logged in

#login_timeObject (readonly)

The last time the user logged in

#nameObject

The user name associated with the account

#passwdObject

The user’s encrypted password. Deprecated in favor of /etc/shadow

#quotaObject

The user’s alloted amount of disk space

#shellObject

The user’s login shell

#uidObject

The user’s user ID

Instance Method Details

#groupsObject

Returns an array of groups the user belongs to.



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'ext/sys/admin.c', line 291

static VALUE user_groups(VALUE self){
   VALUE v_groups, v_group, v_users, v_group_name, v_name, v_result;
   int i;

   v_name   = rb_funcall(self, rb_intern("name"), 0, 0);
   v_result = rb_ary_new();
   v_groups = admin_groups(self);

   /* Iterate over each group, checking its members. If the members includes
    * the user name, we have a match.
    */
   if(!NIL_P(v_groups)){
      for(i = 0; i < RARRAY_LEN(v_groups); i++){
         v_group = RARRAY_PTR(v_groups)[i];
         v_users = rb_funcall(v_group, rb_intern("members"), 0, 0);

         if(RTEST(rb_funcall(v_users, rb_intern("include?"), 1, v_name))){
            v_group_name = rb_funcall(v_group, rb_intern("name"), 0, 0);
            rb_ary_push(v_result, v_group_name);
         }
      }
   }

   return v_result;
}