aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/id/id.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/id/id.c')
-rw-r--r--usr.bin/id/id.c58
1 files changed, 47 insertions, 11 deletions
diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c
index a326aa14c7c7..7ba07daad11e 100644
--- a/usr.bin/id/id.c
+++ b/usr.bin/id/id.c
@@ -55,6 +55,8 @@ static void auditid(void);
#endif
static void group(struct passwd *, bool);
static void maclabel(void);
+static void dir(struct passwd *);
+static void shell(struct passwd *);
static void usage(void);
static struct passwd *who(char *);
@@ -65,23 +67,17 @@ main(int argc, char *argv[])
{
struct group *gr;
struct passwd *pw;
-#ifdef USE_BSM_AUDIT
- bool Aflag;
-#endif
- bool Gflag, Mflag, Pflag;
- bool cflag, gflag, nflag, pflag, rflag, uflag;
+ bool Aflag, Gflag, Mflag, Pflag;
+ bool cflag, dflag, gflag, nflag, pflag, rflag, sflag, uflag;
int ch, combo, error, id;
const char *myname, *optstr;
char loginclass[MAXLOGNAME];
-#ifdef USE_BSM_AUDIT
- Aflag = false;
-#endif
- Gflag = Mflag = Pflag = false;
- cflag = gflag = nflag = pflag = rflag = uflag = false;
+ Aflag = Gflag = Mflag = Pflag = false;
+ cflag = dflag = gflag = nflag = pflag = rflag = sflag = uflag = false;
myname = getprogname();
- optstr = "AGMPacgnpru";
+ optstr = "AGMPacdgnprsu";
if (strcmp(myname, "groups") == 0) {
isgroups = true;
optstr = "";
@@ -114,6 +110,9 @@ main(int argc, char *argv[])
case 'c':
cflag = true;
break;
+ case 'd':
+ dflag = true;
+ break;
case 'g':
gflag = true;
break;
@@ -126,6 +125,9 @@ main(int argc, char *argv[])
case 'r':
rflag = true;
break;
+ case 's':
+ sflag = true;
+ break;
case 'u':
uflag = true;
break;
@@ -142,6 +144,8 @@ main(int argc, char *argv[])
usage();
combo = Aflag + Gflag + Mflag + Pflag + gflag + pflag + uflag;
+ if (combo + dflag + sflag > 1)
+ usage();
if (combo > 1)
usage();
if (combo == 0 && (nflag || rflag))
@@ -185,6 +189,11 @@ main(int argc, char *argv[])
exit(0);
}
+ if (dflag) {
+ dir(pw);
+ exit(0);
+ }
+
if (Gflag) {
group(pw, nflag);
exit(0);
@@ -205,6 +214,11 @@ main(int argc, char *argv[])
exit(0);
}
+ if (sflag) {
+ shell(pw);
+ exit(0);
+ }
+
id_print(pw);
exit(0);
}
@@ -465,6 +479,26 @@ pline(struct passwd *pw)
}
static void
+dir(struct passwd *pw)
+{
+ if (pw == NULL) {
+ if ((pw = getpwuid(getuid())) == NULL)
+ err(1, "getpwuid");
+ }
+ printf("%s\n", pw->pw_dir);
+}
+
+static void
+shell(struct passwd *pw)
+{
+ if (pw == NULL) {
+ if ((pw = getpwuid(getuid())) == NULL)
+ err(1, "getpwuid");
+ }
+ printf("%s\n", pw->pw_shell);
+}
+
+static void
usage(void)
{
if (isgroups)
@@ -481,8 +515,10 @@ usage(void)
" id -M\n"
" id -P [user]\n"
" id -c\n"
+ " id -d [user]\n"
" id -g [-nr] [user]\n"
" id -p [user]\n"
+ " id -s [user]\n"
" id -u [-nr] [user]\n");
exit(1);
}