summaryrefslogtreecommitdiffstats
path: root/usr.sbin/netgroup_mkdb
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2005-05-16 03:12:59 +0000
committerderaadt <deraadt@openbsd.org>2005-05-16 03:12:59 +0000
commit5d4c798f509cbfc8e19192929a96157b8a8f95e8 (patch)
tree1f630c009174b17be25df309894beb2b40228770 /usr.sbin/netgroup_mkdb
parentUse cardbus_matchbyid(). (diff)
downloadwireguard-openbsd-5d4c798f509cbfc8e19192929a96157b8a8f95e8.tar.xz
wireguard-openbsd-5d4c798f509cbfc8e19192929a96157b8a8f95e8.zip
knf
Diffstat (limited to 'usr.sbin/netgroup_mkdb')
-rw-r--r--usr.sbin/netgroup_mkdb/netgroup_mkdb.c36
-rw-r--r--usr.sbin/netgroup_mkdb/str.c6
-rw-r--r--usr.sbin/netgroup_mkdb/util.c59
3 files changed, 48 insertions, 53 deletions
diff --git a/usr.sbin/netgroup_mkdb/netgroup_mkdb.c b/usr.sbin/netgroup_mkdb/netgroup_mkdb.c
index c3b959d609c..fdb90187fab 100644
--- a/usr.sbin/netgroup_mkdb/netgroup_mkdb.c
+++ b/usr.sbin/netgroup_mkdb/netgroup_mkdb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netgroup_mkdb.c,v 1.11 2003/06/26 21:36:39 deraadt Exp $ */
+/* $OpenBSD: netgroup_mkdb.c,v 1.12 2005/05/16 03:12:59 deraadt Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*/
#ifndef lint
-static char *rcsid = "$OpenBSD: netgroup_mkdb.c,v 1.11 2003/06/26 21:36:39 deraadt Exp $";
+static char *rcsid = "$OpenBSD: netgroup_mkdb.c,v 1.12 2005/05/16 03:12:59 deraadt Exp $";
#endif
#include <sys/types.h>
@@ -98,10 +98,9 @@ static char *dbname = _PATH_NETGROUP_DB;
int
main(int argc, char *argv[])
{
+ char buf[MAXPATHLEN], *fname = _PATH_NETGROUP;
DB *db, *ndb, *hdb, *udb;
int ch;
- char buf[MAXPATHLEN];
- char *fname = _PATH_NETGROUP;
while ((ch = getopt(argc, argv, "do:")) != -1)
@@ -161,7 +160,7 @@ main(int argc, char *argv[])
(void) snprintf(buf, sizeof(buf), "%s.tmp", dbname);
db = dbopen(buf, O_RDWR | O_CREAT | O_EXCL,
- (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), DB_HASH, NULL);
+ (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), DB_HASH, NULL);
if (!db)
err(1, "%s", buf);
@@ -201,10 +200,9 @@ ng_load(const char *fname)
{
FILE *fp;
DB *db;
- char *buf;
+ char *buf, *p, *name;
size_t size;
struct nentry *tail, *head, *e;
- char *p, *name;
struct netgroup *ng;
DBT data, key;
@@ -241,7 +239,7 @@ ng_load(const char *fname)
case 1:
warnx("Duplicate entry netgroup `%s'",
- head->n_name);
+ head->n_name);
break;
case -1:
@@ -273,8 +271,7 @@ ng_load(const char *fname)
char fmt[BUFSIZ];
_ng_print(fmt, sizeof(fmt), ng);
errx(1, "no netgroup key for %s", fmt);
- }
- else {
+ } else {
e = NEW(struct nentry);
e->n_type = _NG_GROUP;
e->n_group = ng;
@@ -373,7 +370,7 @@ ng_reventry(DB *db, DB *udb, struct nentry *fe, char *name, size_t s,
case _NG_GROUP:
ng = e->n_group;
p = _ng_makekey(*((char **)(((char *) ng) + s)),
- ng->ng_domain, e->n_size);
+ ng->ng_domain, e->n_size);
xdb = ng_insert(udb, p);
key.data = (u_char *) name;
key.size = strlen(name) + 1;
@@ -434,8 +431,9 @@ ng_reverse(DB *db, size_t s)
struct stringlist *sl;
DBT key, data;
struct nentry *fe;
- DB *udb = dbopen(NULL, O_RDWR | O_CREAT | O_EXCL, 0,
- DB_HASH, NULL);
+ DB *udb;
+
+ udb = dbopen(NULL, O_RDWR | O_CREAT | O_EXCL, 0, DB_HASH, NULL);
if (udb == NULL)
err(1, "dbopen");
@@ -482,9 +480,9 @@ ng_print(struct nentry *e, struct string *str)
case _NG_GROUP:
(void) snprintf(ptr, e->n_size, "(%s,%s,%s)",
- NG_EMPTY(e->n_group->ng_host),
- NG_EMPTY(e->n_group->ng_user),
- NG_EMPTY(e->n_group->ng_domain));
+ NG_EMPTY(e->n_group->ng_host),
+ NG_EMPTY(e->n_group->ng_user),
+ NG_EMPTY(e->n_group->ng_domain));
break;
default:
@@ -543,7 +541,7 @@ ng_dump(DB *db)
ng_print(e, &buf);
(void) fprintf(stderr, "%s\t%s\n", e->n_name,
- buf.s_str ? buf.s_str : "");
+ buf.s_str ? buf.s_str : "");
str_free(&buf);
break;
@@ -575,8 +573,7 @@ ng_rdump(DB *db)
str_init(&buf);
ng_rprint(xdb, &buf);
(void) fprintf(stderr, "%s\t%s\n",
- (char *) key.data,
- buf.s_str ? buf.s_str : "");
+ (char *) key.data, buf.s_str ? buf.s_str : "");
str_free(&buf);
break;
@@ -705,6 +702,7 @@ static void
usage(void)
{
extern const char *__progname;
+
fprintf(stderr, "usage: %s [-o db] file\n", __progname);
exit(1);
}
diff --git a/usr.sbin/netgroup_mkdb/str.c b/usr.sbin/netgroup_mkdb/str.c
index 4b2923c6e33..e312103435a 100644
--- a/usr.sbin/netgroup_mkdb/str.c
+++ b/usr.sbin/netgroup_mkdb/str.c
@@ -30,7 +30,7 @@
*/
#ifndef lint
-static char *rcsid = "$Id: str.c,v 1.2 2004/08/01 18:32:20 deraadt Exp $";
+static char *rcsid = "$Id: str.c,v 1.3 2005/05/16 03:12:59 deraadt Exp $";
#endif
/*
@@ -64,8 +64,8 @@ str_append(struct string *buf, const char *str, int del)
if (buf->s_str == NULL)
buf->s_str = emalloc(len);
else {
- buf->s_str = erealloc(buf->s_str, buf->s_len + len +
- (del ? 2 : 1));
+ buf->s_str = erealloc(buf->s_str, buf->s_len +
+ len + (del ? 2 : 1));
if (del)
buf->s_str[buf->s_len++] = del;
}
diff --git a/usr.sbin/netgroup_mkdb/util.c b/usr.sbin/netgroup_mkdb/util.c
index 7c83232c1ca..d315831c57d 100644
--- a/usr.sbin/netgroup_mkdb/util.c
+++ b/usr.sbin/netgroup_mkdb/util.c
@@ -30,7 +30,7 @@
*/
#ifndef lint
-static char *rcsid = "$Id: util.c,v 1.3 2004/08/01 18:32:20 deraadt Exp $";
+static char *rcsid = "$Id: util.c,v 1.4 2005/05/16 03:12:59 deraadt Exp $";
#endif
#include <err.h>
@@ -45,11 +45,10 @@ static char *rcsid = "$Id: util.c,v 1.3 2004/08/01 18:32:20 deraadt Exp $";
void *
emalloc(size_t s)
{
- void *ptr = malloc(s);
- if (ptr == NULL)
- /* Crappy gcc warning! */
- err(1, "%s", "");
- return ptr;
+ void *ptr = malloc(s);
+ if (ptr == NULL)
+ err(1, "%s", "");
+ return ptr;
}
@@ -59,11 +58,10 @@ emalloc(size_t s)
void *
erealloc(void *p, size_t s)
{
- void *ptr = realloc(p, s);
- if (ptr == NULL)
- /* Crappy gcc warning! */
- err(1, "%s", "");
- return ptr;
+ void *ptr = realloc(p, s);
+ if (ptr == NULL)
+ err(1, "%s", "");
+ return ptr;
}
@@ -74,26 +72,25 @@ erealloc(void *p, size_t s)
char *
getline(FILE *fp, size_t *size)
{
- size_t s, len = 0;
- char *buf = NULL;
- char *ptr;
- int cnt = 1;
+ size_t s, len = 0;
+ char *buf = NULL, *ptr;
+ int cnt = 1;
- while (cnt) {
- if ((ptr = fgetln(fp, &s)) == NULL) {
- *size = len;
- return buf;
- }
- if (ptr[s - 1] == '\n') /* the newline may be missing at EOF */
- s--; /* forget newline */
- if (s && (cnt = (ptr[s - 1] == '\\'))) /* check for \\ */
- s--; /* forget \\ */
+ while (cnt) {
+ if ((ptr = fgetln(fp, &s)) == NULL) {
+ *size = len;
+ return buf;
+ }
+ if (ptr[s - 1] == '\n') /* the newline may be missing at EOF */
+ s--; /* forget newline */
+ if (s && (cnt = (ptr[s - 1] == '\\'))) /* check for \\ */
+ s--; /* forget \\ */
- buf = erealloc(buf, len + s + 1);
- memcpy(buf + len, ptr, s);
- len += s;
- buf[len] = '\0';
- }
- *size = len;
- return buf;
+ buf = erealloc(buf, len + s + 1);
+ memcpy(buf + len, ptr, s);
+ len += s;
+ buf[len] = '\0';
+ }
+ *size = len;
+ return buf;
}