summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-02-14 00:38:50 -0500
committerCameron Katri <me@cameronkatri.com>2021-02-14 00:38:50 -0500
commit737fa5a9bfd3fd968b92fe94936c524ae3685cf3 (patch)
tree7b9d6c1c2fe185c13960519161db489161eb367e
parent1f2ff42d4943d0567b33af1dd0b6f4b5b077f025 (diff)
downloadgetent-darwin-737fa5a9bfd3fd968b92fe94936c524ae3685cf3.tar.gz
getent-darwin-737fa5a9bfd3fd968b92fe94936c524ae3685cf3.tar.zst
getent-darwin-737fa5a9bfd3fd968b92fe94936c524ae3685cf3.zip
Get it compiling
-rw-r--r--getent.c5
-rw-r--r--getutxent.c160
-rw-r--r--utmpx-defines.h3
3 files changed, 11 insertions, 157 deletions
diff --git a/getent.c b/getent.c
index 1b1427e..c8a869a 100644
--- a/getent.c
+++ b/getent.c
@@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
#include <net/if.h>
#include <netinet/if_ether.h>
#include <netinet/in.h> /* for INET6_ADDRSTRLEN */
-#include <rpc/rpcent.h>
#include <assert.h>
#include <ctype.h>
@@ -58,6 +57,10 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include <utmpx.h>
+#include <arpa/nameser_compat.h>
+#include "utmpx-defines.h"
+int setutxdb(int db, const char *file);
+
static int usage(void);
static int parsenum(const char *, unsigned long *);
static int ethers(int, char *[]);
diff --git a/getutxent.c b/getutxent.c
index e0d9932..498f4ae 100644
--- a/getutxent.c
+++ b/getutxent.c
@@ -29,8 +29,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include "namespace.h"
-#include <sys/endian.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <errno.h>
@@ -38,7 +36,9 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <utmpx.h>
#include "utxdb.h"
-#include "un-namespace.h"
+
+#include "utmpx-defines.h"
+#define rounddown(x, y) (((x) / (y)) * (y))
#ifdef __NO_TLS
static FILE *uf = NULL;
@@ -79,7 +79,7 @@ setutxdb(int db, const char *file)
if (db != UTXDB_LOG) {
/* Safety check: never use broken files. */
- if (_fstat(fileno(uf), &sb) != -1 &&
+ if (fstat(fileno(uf), &sb) != -1 &&
sb.st_size % sizeof(struct futx) != 0) {
fclose(uf);
uf = NULL;
@@ -94,155 +94,3 @@ setutxdb(int db, const char *file)
udb = db;
return (0);
}
-
-void
-setutxent(void)
-{
-
- setutxdb(UTXDB_ACTIVE, NULL);
-}
-
-void
-endutxent(void)
-{
-
- if (uf != NULL) {
- fclose(uf);
- uf = NULL;
- }
-}
-
-static int
-getfutxent(struct futx *fu)
-{
-
- if (uf == NULL)
- setutxent();
- if (uf == NULL)
- return (-1);
-
- if (udb == UTXDB_LOG) {
- uint16_t len;
-
-retry:
- if (fread(&len, sizeof(len), 1, uf) != 1)
- return (-1);
- len = be16toh(len);
- if (len == 0) {
- /*
- * XXX: Though zero-size records are valid in theory,
- * they can never occur in practice. Zero-size records
- * indicate file corruption. Seek one byte forward, to
- * see if we can find a record there.
- */
- ungetc('\0', uf);
- goto retry;
- }
- if (len > sizeof *fu) {
- /* Forward compatibility. */
- if (fread(fu, sizeof(*fu), 1, uf) != 1)
- return (-1);
- fseek(uf, len - sizeof(*fu), SEEK_CUR);
- } else {
- /* Partial record. */
- memset(fu, 0, sizeof(*fu));
- if (fread(fu, len, 1, uf) != 1)
- return (-1);
- }
- } else {
- if (fread(fu, sizeof(*fu), 1, uf) != 1)
- return (-1);
- }
- return (0);
-}
-
-struct utmpx *
-getutxent(void)
-{
- struct futx fu;
-
- if (getfutxent(&fu) != 0)
- return (NULL);
- return (futx_to_utx(&fu));
-}
-
-struct utmpx *
-getutxid(const struct utmpx *id)
-{
- struct futx fu;
-
- for (;;) {
- if (getfutxent(&fu) != 0)
- return (NULL);
-
- switch (fu.fu_type) {
- case USER_PROCESS:
- case INIT_PROCESS:
- case LOGIN_PROCESS:
- case DEAD_PROCESS:
- switch (id->ut_type) {
- case USER_PROCESS:
- case INIT_PROCESS:
- case LOGIN_PROCESS:
- case DEAD_PROCESS:
- if (memcmp(fu.fu_id, id->ut_id,
- MIN(sizeof(fu.fu_id), sizeof(id->ut_id))) ==
- 0)
- goto found;
- }
- break;
- default:
- if (fu.fu_type == id->ut_type)
- goto found;
- break;
- }
- }
-
-found:
- return (futx_to_utx(&fu));
-}
-
-struct utmpx *
-getutxline(const struct utmpx *line)
-{
- struct futx fu;
-
- for (;;) {
- if (getfutxent(&fu) != 0)
- return (NULL);
-
- switch (fu.fu_type) {
- case USER_PROCESS:
- case LOGIN_PROCESS:
- if (strncmp(fu.fu_line, line->ut_line,
- MIN(sizeof(fu.fu_line), sizeof(line->ut_line))) ==
- 0)
- goto found;
- break;
- }
- }
-
-found:
- return (futx_to_utx(&fu));
-}
-
-struct utmpx *
-getutxuser(const char *user)
-{
- struct futx fu;
-
- for (;;) {
- if (getfutxent(&fu) != 0)
- return (NULL);
-
- switch (fu.fu_type) {
- case USER_PROCESS:
- if (strncmp(fu.fu_user, user, sizeof(fu.fu_user)) == 0)
- goto found;
- break;
- }
- }
-
-found:
- return (futx_to_utx(&fu));
-}
diff --git a/utmpx-defines.h b/utmpx-defines.h
new file mode 100644
index 0000000..0aaa1e3
--- /dev/null
+++ b/utmpx-defines.h
@@ -0,0 +1,3 @@
+#define UTXDB_ACTIVE 0
+#define UTXDB_LASTLOGIN 1
+#define UTXDB_LOG 2