SPVM-Sys

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

      setgrent

      endgrent

      getgrent

      getgroups

      setgroups

      getpwuid

      getpwnam

      getgrgid

      getgrnam


0.506 2023-12-01
  [Incompatible Changes]

lib/SPVM/Sys.pm  view on Meta::CPAN

C<static method getgroups : int[] ();>

Returns the supplementary group IDs of the calling process.

=head2 setgroups

C<static method setgroups : void ($group_ids : int[]);>

Sets the supplementary group IDs for the calling process.

=head2 getpwuid

C<static method getpwuid : L<Sys::User::Passwd|SPVM::Sys::User::Passwd> ($id : int);>

Searches a password entry given The user ID $id. If found, returns the password entry, otherwise return undef.

=head2 getpwnam

C<static method getpwnam : L<Sys::User::Passwd|SPVM::Sys::User::Passwd> ($name : string);>

Searches a password entry given The user name $name. If found, returns the password entry, otherwise return undef.

=head2 getgrgid

lib/SPVM/Sys.spvm  view on Meta::CPAN

    
    Sys::User->getgroups($group_ids_length, $group_ids);
    
    return $group_ids;
  }
  
  static method setgroups : void ($group_ids : int[]) {
    Sys::User->setgroups($group_ids);
  }
  
  static method getpwuid : Sys::User::Passwd ($id : int) {
    
    my $pwent = Sys::User->getpwuid($id);
    
    return $pwent;
  }
  
  static method getpwnam : Sys::User::Passwd ($name : string) {
    
    my $pwent = Sys::User->getpwnam($name);
    
    return $pwent;
  }

lib/SPVM/Sys/User.c  view on Meta::CPAN

  int32_t status = setgroups(groups_length, (gid_t*)groups);
  if (status == -1) {
    env->die(env, stack, "[System Error]setgroups() failed:%s.", env->strerror_nolen(env, stack, errno), __func__, FILE_NAME, __LINE__);
    return SPVM_NATIVE_C_BASIC_TYPE_ID_ERROR_SYSTEM_CLASS;
  }
  stack[0].ival = status;
  return 0;
#endif
}

int32_t SPVM__Sys__User__getpwuid(SPVM_ENV* env, SPVM_VALUE* stack) {
  
#if defined(_WIN32)
  env->die(env, stack, "Sys::User#getpwuid method is not supported in this system(defined(_WIN32)).", __func__, FILE_NAME, __LINE__);
  return SPVM_NATIVE_C_BASIC_TYPE_ID_ERROR_NOT_SUPPORTED_CLASS;
#else
  int32_t error_id = 0;
  
  int32_t uid = stack[0].ival;
  
  errno = 0;
  struct passwd* pwent = getpwuid(uid);
  
  if (errno != 0) {
    env->die(env, stack, "[System Error]getpwuid() failed:%s.", env->strerror_nolen(env, stack, errno), __func__, FILE_NAME, __LINE__);
    return SPVM_NATIVE_C_BASIC_TYPE_ID_ERROR_SYSTEM_CLASS;
  }
  if (pwent == NULL) {
    stack[0].oval = NULL;
  }
  else {
    void* obj_sys_ent_passwd = env->new_pointer_object_by_name(env, stack, "Sys::User::Passwd", pwent, &error_id, __func__, FILE_NAME, __LINE__);
    if (error_id) { return error_id; }
    stack[0].oval = obj_sys_ent_passwd;
  }

lib/SPVM/Sys/User.pm  view on Meta::CPAN

C<static method setgroups : void ($groups : int[]);>

Calls the L<setgroups|https://linux.die.net/man/2/setgroups> function.

Exceptions:

If the setgroups function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class.

In Windows the following exception is thrown. setgroups is not supported in this system(defined(_WIN32)).

=head2 getpwuid

C<static method getpwuid : L<Sys::User::Passwd|SPVM::Sys::User::Passwd> ($id : int);>

Calls the L<getpwuid|https://linux.die.net/man/3/getpwuid> function.

And if its return value is NULL, returns undef, otherwise creates a new L<Sys::User::Passwd|SPVM::Sys::User::Passwd> object whose pointer is set to function's return value, and returns it.

Exceptions:

If the getpwuid function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class.

In Windows the following exception is thrown. getpwuid is not supported in this system(defined(_WIN32)).

=head2 getpwnam

C<static method getpwnam : L<Sys::User::Passwd|SPVM::Sys::User::Passwd> ($name : string);>

Calls the L<getpwnam|https://linux.die.net/man/3/getpwnam> function.

And if its return value is NULL, returns undef, otherwise creates a new L<Sys::User::Passwd|SPVM::Sys::User::Passwd> object whose pointer is set to function's return value, and returns it.

Exceptions:

lib/SPVM/Sys/User.spvm  view on Meta::CPAN

  native static method setgrent : void ();
  
  native static method endgrent : void ();
  
  native static method getgrent : Sys::User::Group ();
  
  native static method getgroups : int ($size : int, $list : int[]);
  
  native static method setgroups : int ($groups : int[]);
  
  native static method getpwuid : Sys::User::Passwd ($id : int);
  
  native static method getpwnam : Sys::User::Passwd ($name : string);
  
  native static method getgrgid : Sys::User::Group ($id : int);
  
  native static method getgrnam : Sys::User::Group ($name : string);
}



( run in 0.400 second using v1.01-cache-2.11-cpan-8d75d55dd25 )