diff options
author | Peter Tribble <peter.tribble@gmail.com> | 2018-08-13 20:48:27 +0100 |
---|---|---|
committer | Robert Mustacchi <rm@joyent.com> | 2018-08-17 02:19:26 +0000 |
commit | e5ecfaa0ff00b00d0b97e8638701ff77caeeab1d (patch) | |
tree | 6bb2bfb5eaa28a556412d26d560eb72f1d40ada7 /usr/src/cmd/getent | |
parent | 70ee30a511f4abfd1b9cdf25495a219fe131829a (diff) | |
download | illumos-gate-e5ecfaa0ff00b00d0b97e8638701ff77caeeab1d.tar.gz |
9726 getent could list the attr databases
Reviewed by: Yuri Pankov <yuripv@yuripv.net>
Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Gergő Mihály Doma <domag02@gmail.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Diffstat (limited to 'usr/src/cmd/getent')
-rw-r--r-- | usr/src/cmd/getent/Makefile | 6 | ||||
-rw-r--r-- | usr/src/cmd/getent/dogetauthattr.c | 88 | ||||
-rw-r--r-- | usr/src/cmd/getent/dogetexecattr.c | 93 | ||||
-rw-r--r-- | usr/src/cmd/getent/dogetprofattr.c | 87 | ||||
-rw-r--r-- | usr/src/cmd/getent/dogetuserattr.c | 101 | ||||
-rw-r--r-- | usr/src/cmd/getent/getent.c | 5 | ||||
-rw-r--r-- | usr/src/cmd/getent/getent.h | 5 |
7 files changed, 384 insertions, 1 deletions
diff --git a/usr/src/cmd/getent/Makefile b/usr/src/cmd/getent/Makefile index 571f49b150..c68e2d91fe 100644 --- a/usr/src/cmd/getent/Makefile +++ b/usr/src/cmd/getent/Makefile @@ -31,22 +31,26 @@ PROG= getent include ../Makefile.cmd OBJECTS= \ + dogetauthattr.o \ dogetethers.o \ + dogetexecattr.o \ dogetgr.o \ dogethost.o \ dogetipnodes.o \ dogetnet.o \ dogetnetmask.o \ + dogetprofattr.o \ dogetproject.o \ dogetproto.o \ dogetpw.o \ dogetsp.o \ dogetserv.o \ + dogetuserattr.o \ getent.o SRCS= $(OBJECTS:.o=.c) -LDLIBS += -lsocket -lnsl -lproject +LDLIBS += -lsecdb -lsocket -lnsl -lproject # # for message catalog diff --git a/usr/src/cmd/getent/dogetauthattr.c b/usr/src/cmd/getent/dogetauthattr.c new file mode 100644 index 0000000000..d2327d3fe1 --- /dev/null +++ b/usr/src/cmd/getent/dogetauthattr.c @@ -0,0 +1,88 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2018 Peter Tribble. + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <auth_attr.h> +#include "getent.h" + +static int +putauthattr(const authattr_t *auth, FILE *fp) +{ + int i; + kva_t *attrs; + kv_t *data; + + if (auth == NULL) + return (1); + + if (fprintf(fp, "%s:%s:%s:%s:%s:", + auth->name != NULL ? auth->name : "", + auth->res1 != NULL ? auth->res1 : "", + auth->res2 != NULL ? auth->res2 : "", + auth->short_desc != NULL ? auth->short_desc : "", + auth->long_desc != NULL ? auth->long_desc : "") == EOF) + return (1); + attrs = auth->attr; + if (attrs != NULL) { + data = attrs->data; + for (i = 0; i < attrs->length; i++) { + if (fprintf(fp, "%s=%s%s", + data[i].key != NULL ? data[i].key : "", + data[i].value != NULL ? data[i].value : "", + i < (attrs->length)-1 ? ";" : "") == EOF) + return (1); + } + } + if (putc('\n', fp) == EOF) + return (1); + return (0); +} + +int +dogetauthattr(const char **list) +{ + authattr_t *pauth; + int rc = EXC_SUCCESS; + + if (list == NULL || *list == NULL) { + setauthattr(); + while ((pauth = getauthattr()) != NULL) + (void) putauthattr(pauth, stdout); + endauthattr(); + } else { + for (; *list != NULL; list++) { + pauth = getauthnam(*list); + if (pauth == NULL) + rc = EXC_NAME_NOT_FOUND; + else + (void) putauthattr(pauth, stdout); + } + } + + return (rc); +} diff --git a/usr/src/cmd/getent/dogetexecattr.c b/usr/src/cmd/getent/dogetexecattr.c new file mode 100644 index 0000000000..15c83c45c8 --- /dev/null +++ b/usr/src/cmd/getent/dogetexecattr.c @@ -0,0 +1,93 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2018 Peter Tribble. + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <exec_attr.h> +#include "getent.h" + +static int +putexecattr(const execattr_t *exec, FILE *fp) +{ + int i; + kva_t *attrs; + kv_t *data; + + if (exec == NULL) + return (1); + + if (fprintf(fp, "%s:%s:%s:%s:%s:%s:", + exec->name != NULL ? exec->name : "", + exec->policy != NULL ? exec->policy : "", + exec->type != NULL ? exec->type : "", + exec->res1 != NULL ? exec->res1 : "", + exec->res2 != NULL ? exec->res2 : "", + exec->id != NULL ? exec->id : "") == EOF) + return (1); + attrs = exec->attr; + if (attrs != NULL) { + data = attrs->data; + for (i = 0; i < attrs->length; i++) { + if (fprintf(fp, "%s=%s%s", + data[i].key != NULL ? data[i].key : "", + data[i].value != NULL ? data[i].value : "", + i < (attrs->length)-1 ? ";" : "") == EOF) + return (1); + } + } + if (putc('\n', fp) == EOF) + return (1); + return (0); +} + +int +dogetexecattr(const char **list) +{ + execattr_t *pexec; + int rc = EXC_SUCCESS; + + if (list == NULL || *list == NULL) { + setexecattr(); + while ((pexec = getexecattr()) != NULL) + (void) putexecattr(pexec, stdout); + endexecattr(); + } else { + for (; *list != NULL; list++) { + pexec = getexecprof(*list, NULL, NULL, GET_ALL); + if (pexec == NULL) { + rc = EXC_NAME_NOT_FOUND; + } else { + for (; pexec != NULL; pexec = pexec->next) { + (void) putexecattr(pexec, stdout); + } + + } + } + } + + return (rc); +} diff --git a/usr/src/cmd/getent/dogetprofattr.c b/usr/src/cmd/getent/dogetprofattr.c new file mode 100644 index 0000000000..20bfbf7fe0 --- /dev/null +++ b/usr/src/cmd/getent/dogetprofattr.c @@ -0,0 +1,87 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2018 Peter Tribble. + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <prof_attr.h> +#include "getent.h" + +static int +putprofattr(const profattr_t *prof, FILE *fp) +{ + int i; + kva_t *attrs; + kv_t *data; + + if (prof == NULL) + return (1); + + if (fprintf(fp, "%s:%s:%s:%s:", + prof->name != NULL ? prof->name : "", + prof->res1 != NULL ? prof->res1 : "", + prof->res2 != NULL ? prof->res2 : "", + prof->desc != NULL ? prof->desc : "") == EOF) + return (1); + attrs = prof->attr; + if (attrs != NULL) { + data = attrs->data; + for (i = 0; i < attrs->length; i++) { + if (fprintf(fp, "%s=%s%s", + data[i].key != NULL ? data[i].key : "", + data[i].value != NULL ? data[i].value : "", + i < (attrs->length)-1 ? ";" : "") == EOF) + return (1); + } + } + if (putc('\n', fp) == EOF) + return (1); + return (0); +} + +int +dogetprofattr(const char **list) +{ + profattr_t *pprof; + int rc = EXC_SUCCESS; + + if (list == NULL || *list == NULL) { + setprofattr(); + while ((pprof = getprofattr()) != NULL) + (void) putprofattr(pprof, stdout); + endprofattr(); + } else { + for (; *list != NULL; list++) { + pprof = getprofnam(*list); + if (pprof == NULL) + rc = EXC_NAME_NOT_FOUND; + else + (void) putprofattr(pprof, stdout); + } + } + + return (rc); +} diff --git a/usr/src/cmd/getent/dogetuserattr.c b/usr/src/cmd/getent/dogetuserattr.c new file mode 100644 index 0000000000..8d508f942e --- /dev/null +++ b/usr/src/cmd/getent/dogetuserattr.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2018 Peter Tribble. + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include <stdio.h> +#include <pwd.h> +#include <stdlib.h> +#include <errno.h> +#include <user_attr.h> +#include "getent.h" + +static int +putuserattr(const userattr_t *user, FILE *fp) +{ + int i; + kva_t *attrs; + kv_t *data; + + if (user == NULL) + return (1); + + if (fprintf(fp, "%s:%s:%s:%s:", + user->name != NULL ? user->name : "", + user->qualifier != NULL ? user->res1 : "", + user->res1 != NULL ? user->res1 : "", + user->res2 != NULL ? user->res2 : "") == EOF) + return (1); + attrs = user->attr; + if (attrs != NULL) { + data = attrs->data; + for (i = 0; i < attrs->length; i++) { + if (fprintf(fp, "%s=%s%s", + data[i].key != NULL ? data[i].key : "", + data[i].value != NULL ? data[i].value : "", + i < (attrs->length)-1 ? ";" : "") == EOF) + return (1); + } + } + if (putc('\n', fp) == EOF) + return (1); + return (0); +} + +int +dogetuserattr(const char **list) +{ + struct passwd *pwp; + userattr_t *puser; + int rc = EXC_SUCCESS; + char *ptr; + uid_t uid; + + if (list == NULL || *list == NULL) { + setuserattr(); + while ((puser = getuserattr()) != NULL) + (void) putuserattr(puser, stdout); + enduserattr(); + } else { + for (; *list != NULL; list++) { + uid = strtoul(*list, &ptr, 10); + if (*ptr == '\0' && errno == 0) { + if ((pwp = getpwuid(uid)) == NULL) { + puser = getusernam(*list); + } else { + puser = getusernam(pwp->pw_name); + } + } else { + puser = getusernam(*list); + } + if (puser == NULL) + rc = EXC_NAME_NOT_FOUND; + else + (void) putuserattr(puser, stdout); + } + } + + return (rc); +} diff --git a/usr/src/cmd/getent/getent.c b/usr/src/cmd/getent/getent.c index 799568764e..782034d956 100644 --- a/usr/src/cmd/getent/getent.c +++ b/usr/src/cmd/getent/getent.c @@ -20,6 +20,7 @@ * CDDL HEADER END */ /* + * Copyright (c) 2018 Peter Tribble. * Copyright (c) 2014 Gary Mills * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -51,6 +52,10 @@ static struct table t[] = { { "networks", dogetnet }, { "netmasks", dogetnetmask }, { "project", dogetproject }, + { "auth_attr", dogetauthattr }, + { "exec_attr", dogetexecattr }, + { "prof_attr", dogetprofattr }, + { "user_attr", dogetuserattr }, { NULL, NULL } }; diff --git a/usr/src/cmd/getent/getent.h b/usr/src/cmd/getent/getent.h index 049a2536c3..99b5cac075 100644 --- a/usr/src/cmd/getent/getent.h +++ b/usr/src/cmd/getent/getent.h @@ -20,6 +20,7 @@ * CDDL HEADER END */ /* + * Copyright (c) 2018 Peter Tribble. * Copyright (c) 2014 Gary Mills * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -51,6 +52,10 @@ extern int dogetproto(const char **); extern int dogetethers(const char **); extern int dogetnetmask(const char **); extern int dogetproject(const char **); +extern int dogetauthattr(const char **); +extern int dogetexecattr(const char **); +extern int dogetprofattr(const char **); +extern int dogetuserattr(const char **); #ifdef __cplusplus } |