100277c9Gary Mills/*
200277c9Gary Mills * CDDL HEADER START
300277c9Gary Mills *
400277c9Gary Mills * The contents of this file are subject to the terms of the
500277c9Gary Mills * Common Development and Distribution License (the "License").
600277c9Gary Mills * You may not use this file except in compliance with the License.
700277c9Gary Mills *
800277c9Gary Mills * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
900277c9Gary Mills * or http://www.opensolaris.org/os/licensing.
1000277c9Gary Mills * See the License for the specific language governing permissions
1100277c9Gary Mills * and limitations under the License.
1200277c9Gary Mills *
1300277c9Gary Mills * When distributing Covered Code, include this CDDL HEADER in each
1400277c9Gary Mills * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1500277c9Gary Mills * If applicable, add the following below this CDDL HEADER, with the
1600277c9Gary Mills * fields enclosed by brackets "[]" replaced with your own identifying
1700277c9Gary Mills * information: Portions Copyright [yyyy] [name of copyright owner]
1800277c9Gary Mills *
1900277c9Gary Mills * CDDL HEADER END
2000277c9Gary Mills */
2100277c9Gary Mills
2200277c9Gary Mills/*
232c5ec7aPeter Tribble * Copyright (c) 2018 Peter Tribble.
2400277c9Gary Mills * Copyright (c) 2014 Gary Mills
2500277c9Gary Mills * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2600277c9Gary Mills * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
2700277c9Gary Mills * Use is subject to license terms.
2800277c9Gary Mills */
2900277c9Gary Mills
3000277c9Gary Mills#include <stdio.h>
3100277c9Gary Mills#include <shadow.h>
3200277c9Gary Mills#include <stdlib.h>
3300277c9Gary Mills#include <errno.h>
3400277c9Gary Mills#include "getent.h"
3500277c9Gary Mills
3600277c9Gary Mills/*
3700277c9Gary Mills * getspnam - get entries from shadow database
3800277c9Gary Mills */
3900277c9Gary Millsint
4000277c9Gary Millsdogetsp(const char **list)
4100277c9Gary Mills{
4200277c9Gary Mills	struct spwd *sp;
4300277c9Gary Mills	int rc = EXC_SUCCESS;
4400277c9Gary Mills
4500277c9Gary Mills
4600277c9Gary Mills	if (list == NULL || *list == NULL) {
4700277c9Gary Mills		setspent();
4800277c9Gary Mills		while ((sp = getspent()) != NULL)
4900277c9Gary Mills			(void) putspent(sp, stdout);
5000277c9Gary Mills		endspent();
5100277c9Gary Mills	} else {
5200277c9Gary Mills		for (; *list != NULL; list++) {
5300277c9Gary Mills			sp = getspnam(*list);
5400277c9Gary Mills			if (sp == NULL)
5500277c9Gary Mills				rc = EXC_NAME_NOT_FOUND;
5600277c9Gary Mills			else
5700277c9Gary Mills				(void) putspent(sp, stdout);
5800277c9Gary Mills		}
5900277c9Gary Mills	}
6000277c9Gary Mills
6100277c9Gary Mills	return (rc);
6200277c9Gary Mills}