Changeset ffa71f1 in rtems


Ignore:
Timestamp:
Nov 17, 2014, 6:53:01 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
c3350e7d
Parents:
395e5d4
git-author:
Sebastian Huber <sebastian.huber@…> (11/17/14 06:53:01)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/20/14 09:30:22)
Message:

libcsupport: Implement getgroups()

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/getgroups.c

    r395e5d4 rffa71f1  
    1111
    1212#include <sys/types.h>
     13#include <grp.h>
     14#include <pwd.h>
     15#include <string.h>
    1316#include <unistd.h>
     17
     18#include <rtems/seterr.h>
    1419
    1520/**
     
    1722 */
    1823int getgroups(
    19   int    gidsetsize __attribute__((unused)),
    20   gid_t  grouplist[] __attribute__((unused))
     24  int    gidsetsize,
     25  gid_t  grouplist[]
    2126)
    2227{
    23   return 0;  /* no supplemental group ids */
     28  int rv;
     29  struct passwd pwd;
     30  struct passwd *pwd_res;
     31  char buf[256];
     32  gid_t gid;
     33  const char *user;
     34  struct group *grp;
     35
     36  rv = getpwuid_r(getuid(), &pwd, &buf[0], sizeof(buf), &pwd_res);
     37  if (rv != 0) {
     38    return rv;
     39  }
     40
     41  gid = pwd.pw_gid;
     42  user = pwd.pw_name;
     43
     44  setgrent();
     45
     46  while ((grp = getgrent()) != NULL) {
     47    char **mem = &grp->gr_mem[0];
     48
     49    if (grp->gr_gid == gid) {
     50      continue;
     51    }
     52
     53    while (*mem != NULL) {
     54      if (strcmp(*mem, user) == 0) {
     55        if (rv < gidsetsize) {
     56          grouplist[rv] = grp->gr_gid;
     57        }
     58
     59        ++rv;
     60
     61        break;
     62      }
     63
     64      ++mem;
     65    }
     66  }
     67
     68  endgrent();
     69
     70  if (gidsetsize == 0 || rv <= gidsetsize) {
     71    return rv;
     72  } else {
     73    rtems_set_errno_and_return_minus_one(EINVAL);
     74  }
    2475}
  • testsuites/libtests/pwdgrp01/init.c

    r395e5d4 rffa71f1  
    1818
    1919#include <sys/stat.h>
     20#include <sys/types.h>
     21#include <errno.h>
    2022#include <grp.h>
    2123#include <pwd.h>
    2224#include <stdio.h>
     25#include <unistd.h>
    2326
    2427#include "tmacros.h"
     
    7073  struct group *grp_res;
    7174  char buf[256];
     75  gid_t grps[5];
    7276
    7377  rv = mkdir("/etc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
     
    8185  create_file(
    8286    "/etc/group",
     87    "A::1:moop,u,v,w\n"
     88    "B::2:moop\n"
    8389    "blub:bar:3:moop\n"
     90    "C::4:l,m,n,moop\n"
     91    "D::5:moop,moop\n"
     92    "E::6:x\n"
     93    "E::7:y,z\n"
     94    "F::8:s,moop,t\n"
    8495  );
    8596
     
    107118  rtems_test_assert(&grp == grp_res);
    108119  assert_grp(grp_res);
     120
     121  rv = setuid(0);
     122  rtems_test_assert(rv == 0);
     123
     124  errno = 0;
     125  rv = getgroups(0, NULL);
     126  rtems_test_assert(rv == -1);
     127  rtems_test_assert(errno == EINVAL);
     128
     129  rv = setuid(1);
     130  rtems_test_assert(rv == 0);
     131
     132  rv = getgroups(0, NULL);
     133  rtems_test_assert(rv == 5);
     134
     135  errno = 0;
     136  rv = getgroups(1, &grps[0]);
     137  rtems_test_assert(rv == -1);
     138  rtems_test_assert(errno == EINVAL);
     139
     140  memset(&grps[0], 0xff, sizeof(grps));
     141  rv = getgroups(5, &grps[0]);
     142  rtems_test_assert(rv == 5);
     143  rtems_test_assert(grps[0] == 1);
     144  rtems_test_assert(grps[1] == 2);
     145  rtems_test_assert(grps[2] == 4);
     146  rtems_test_assert(grps[3] == 5);
     147  rtems_test_assert(grps[4] == 8);
    109148}
    110149
     
    127166
    128167#define CONFIGURE_MAXIMUM_TASKS 1
     168#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
     169#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
    129170
    130171#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
  • testsuites/psxtests/psxid01/init.c

    r395e5d4 rffa71f1  
    3535
    3636  gid = getegid();
     37  rtems_test_assert( gid == 0 );
    3738  printf( "getegid = %d\n", gid );
    3839
    3940  gid = getgid();
     41  rtems_test_assert( gid == 0 );
    4042  printf( "getgid = %d\n", gid );
    4143
     
    4547
    4648  gid = getegid();
     49  rtems_test_assert( gid == 0 );
    4750  printf( "getegid = %d\n", gid );
    4851
    4952  gid = getgid();
     53  rtems_test_assert( gid == 5 );
    5054  printf( "getgid = %d\n", gid );
    5155
     56  puts( "setegid(5)" );
     57  sc = setegid(5);
     58  rtems_test_assert( sc == 0 );
     59
     60  gid = getegid();
     61  rtems_test_assert( gid == 5 );
     62  printf( "getegid = %d\n", gid );
     63
     64  gid = getgid();
     65  rtems_test_assert( gid == 5 );
     66  printf( "getgid = %d\n", gid );
     67
     68  puts( "setgid(0)" );
     69  sc = setgid(0);
     70  rtems_test_assert( sc == 0 );
     71
     72  puts( "setegid(0)" );
     73  sc = setegid(0);
     74  rtems_test_assert( sc == 0 );
     75
     76  errno = 0;
    5277  puts( "setpgid(getpid(), 10) - ENOSYS" );
    5378  sc = setpgid( getpid(), 10 );
     
    6287
    6388  uid = geteuid();
     89  rtems_test_assert( uid == 0 );
    6490  printf( "geteuid = %d\n", uid );
    6591
    6692  uid = getuid();
     93  rtems_test_assert( uid == 0 );
    6794  printf( "getuid = %d\n", uid );
    6895
     
    7299
    73100  uid = geteuid();
     101  rtems_test_assert( uid == 0 );
    74102  printf( "geteuid = %d\n", uid );
    75103
    76104  uid = getuid();
     105  rtems_test_assert( uid == 5 );
    77106  printf( "getuid = %d\n", uid );
    78107
     108  puts( "seteuid(5)" );
     109  sc = seteuid(5);
     110  rtems_test_assert( sc == 0 );
     111
     112  uid = geteuid();
     113  rtems_test_assert( uid == 5 );
     114  printf( "geteuid = %d\n", uid );
     115
     116  uid = getuid();
     117  rtems_test_assert( uid == 5 );
     118  printf( "getuid = %d\n", uid );
     119
     120  puts( "seteuid(0)" );
     121  sc = seteuid(0);
     122  rtems_test_assert( sc == 0 );
     123
     124  puts( "setuid(0)" );
     125  sc = setuid(0);
     126  rtems_test_assert( sc == 0 );
    79127}
    80128
     
    107155  pid = getpgrp();
    108156  printf( "getpgrp returned %d\n", pid );
    109 
    110   puts( "getgroups - return 0 - OK" );
    111   sc = getgroups( 0, NULL );
    112   rtems_test_assert( sc == 0 );
    113  
    114157}
    115158
  • testsuites/psxtests/psxid01/psxid01.scn

    r395e5d4 rffa71f1  
    1 *** TEST ID 01 ***
     1*** BEGIN OF TEST PSXID 1 ***
    22getegid = 0
    33getgid = 0
     
    55getegid = 0
    66getgid = 5
     7setegid(5)
     8getegid = 5
     9getgid = 5
     10setgid(0)
     11setegid(0)
    712setpgid(getpid(), 10) - ENOSYS
    813
     
    1217geteuid = 0
    1318getuid = 5
     19seteuid(5)
     20geteuid = 5
     21getuid = 5
     22seteuid(0)
     23setuid(0)
    1424
    1525getpid = 1
     
    1929getpgrp - return local node - OK
    2030getpgrp returned 1
    21 getgroups - return 0 - OK
    2231
    2332setuid(5)
     
    2736getlogin_r(NULL, LOGIN_NAME_MAX) -- EFAULT
    2837getlogin_r(buffer, 0) -- ERANGE
    29 *** END OF TEST ID 01 ***
     38*** END OF TEST PSXID 1 ***
Note: See TracChangeset for help on using the changeset viewer.