Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:19

0001 /**
0002  * @file
0003  * 
0004  * @brief ID Command Implementation
0005  */
0006 
0007 /*
0008  * Copyright (c) 2001 Fernando Ruiz Casas <fruizcasas@gmail.com>
0009  *
0010  *  The license and distribution terms for this file may be
0011  *  found in the file LICENSE in this distribution or at
0012  *  http://www.rtems.org/license/LICENSE.
0013  */
0014 
0015 #ifdef HAVE_CONFIG_H
0016 #include "config.h"
0017 #endif
0018 
0019 
0020 #include <stdio.h>
0021 #include <unistd.h>
0022 #include <string.h>
0023 #include <errno.h>
0024 #include <pwd.h>
0025 #include <grp.h>
0026 
0027 #include <rtems.h>
0028 #include <rtems/shell.h>
0029 #include "internal.h"
0030 
0031 static int rtems_shell_main_id(
0032   int   argc RTEMS_UNUSED,
0033   char *argv[] RTEMS_UNUSED
0034 )
0035 {
0036   struct passwd *pwd;
0037   struct group  *grp;
0038 
0039   pwd = getpwuid(getuid());
0040   grp = getgrgid(getgid());
0041   printf(
0042     "uid=%d(%s),gid=%d(%s),",
0043     getuid(),
0044     (pwd) ? pwd->pw_name : "",
0045     getgid(),
0046     (grp) ? grp->gr_name : ""
0047   );
0048   pwd = getpwuid(geteuid());
0049   grp = getgrgid(getegid());
0050   printf(
0051     "euid=%d(%s),egid=%d(%s)\n",
0052     geteuid(),
0053     (pwd) ? pwd->pw_name : "",
0054     getegid(),
0055     (grp) ? grp->gr_name : ""
0056   );
0057   return 0;
0058 }
0059 
0060 rtems_shell_cmd_t rtems_shell_ID_Command = {
0061   "id",                                      /* name */
0062   "show uid, gid, euid, and egid",           /* usage */
0063   "misc",                                    /* topic */
0064   rtems_shell_main_id,                       /* command */
0065   NULL,                                      /* alias */
0066   NULL                                       /* next */
0067 };