#include <utmpx-darwin.h>
#include <utmpx_thread.h>
#include <asl.h>
-#include <asl_private.h>
-#include <asl_store.h>
#include <pwd.h>
#include <stddef.h>
#include <ttyent.h>
#endif /* UTMP_COMPAT */
+#if ASL_API_VERSION < 20131108
+#include <asl_private.h>
+#include <asl_store.h>
+#endif
+
__private_extern__ const char __utx_magic__[UTMPX_MAGIC] = __UTX_MAGIC__;
extern const char _utmpx_vers[]; /* in utmpx.c */
+#if ASL_API_VERSION < 20131108
static void msg2lastlogx(const aslmsg, struct lastlogx *);
static void msg2utmpx(const aslmsg, struct utmpx *);
static void utmpx2msg(const struct utmpx *, aslmsg);
+#else
+static void msg2lastlogx(asl_object_t, struct lastlogx *);
+static void msg2utmpx(asl_object_t, struct utmpx *);
+static void utmpx2msg(const struct utmpx *, asl_object_t);
+#endif
static size_t pw_size = 0;
struct lastlogx *
getlastlogxbyname(const char *user, struct lastlogx *lx)
{
+#if ASL_API_VERSION < 20131108
aslmsg m;
asl_msg_t *qm[1];
asl_search_result_t query, *res;
uint32_t status;
+ asl_store_t *store = NULL;
uint64_t cmax;
+#else
+ asl_object_t m, query, res;
+ size_t cmax;
+#endif
struct lastlogx *result = NULL;
- asl_store_t *store;
if (!user || !*user) return NULL;
- store = NULL;
+#if ASL_API_VERSION < 20131108
status = asl_store_open_read(NULL, &store);
if (status != 0) return NULL;
if (store == NULL) return NULL;
+#endif
/*
* We search for the last LASTLOG_FACILITY entry that has the
* ut_user entry matching the user's name.
*/
- if ((m = asl_new(ASL_TYPE_QUERY)) == NULL)
+ m = asl_new(ASL_TYPE_QUERY);
+ if (m == NULL)
{
+#if ASL_API_VERSION < 20131108
asl_store_close(store);
+#endif
return NULL;
}
asl_set_query(m, FACILITY, LASTLOG_FACILITY, ASL_QUERY_OP_EQUAL);
asl_set_query(m, "ut_user", user, ASL_QUERY_OP_EQUAL);
+
+#if ASL_API_VERSION < 20131108
qm[0] = (asl_msg_t *)m;
query.count = 1;
query.msg = qm;
+#else
+ query = asl_new(ASL_TYPE_LIST);
+ if (query == NULL)
+ {
+ asl_release(m);
+ return NULL;
+ }
+
+ asl_append(query, m);
+ asl_release(m);
+#endif
res = NULL;
cmax = 0;
+#if ASL_API_VERSION < 20131108
asl_store_match_timeout(store, &query, &res, &cmax, -1, 1, -1, ASL_QUERY_TIMEOUT);
asl_store_close(store);
asl_free(m);
+#else
+ res = asl_match(NULL, query, &cmax, -1, 1, ASL_QUERY_TIMEOUT, ASL_MATCH_DIRECTION_REVERSE);
+ asl_release(query);
+#endif
- if (status != 0) return NULL;
if (res == NULL) return NULL;
+#if ASL_API_VERSION < 20131108
m = aslresponse_next(res);
+#else
+ m = asl_next(res);
+#endif
+
if (m == NULL)
{
+#if ASL_API_VERSION < 20131108
aslresponse_free(res);
+#else
+ asl_release(res);
+#endif
return NULL;
}
{
if ((lx = (struct lastlogx *)malloc(sizeof(*lx))) == NULL)
{
+#if ASL_API_VERSION < 20131108
aslresponse_free(res);
+#else
+ asl_release(res);
+#endif
return NULL;
}
}
msg2lastlogx(m, lx);
+#if ASL_API_VERSION < 20131108
aslresponse_free(res);
+#else
+ asl_release(res);
+#endif
result = lx;
return result;
#define SGET(e,p) if ((cp = asl_get(m, __STRING(ut_##e))) != NULL) \
strncpy(u->p##_##e, cp, sizeof(u->p##_##e))
-/* fill in a struct lastlogx from a aslmsg */
+/* fill in a struct lastlogx from an ASL message */
static void
+#if ASL_API_VERSION < 20131108
msg2lastlogx(const aslmsg m, struct lastlogx *u)
+#else
+msg2lastlogx(asl_object_t m, struct lastlogx *u)
+#endif
{
const char *cp;
SGET(host, ll);
}
-/* fill in a struct utmpx from a aslmsg */
+/* fill in a struct utmpx from an ASL message */
static void
-msg2utmpx(const aslmsg m, struct utmpx *u)
+#if ASL_API_VERSION < 20131108
+msg2utmpx(aslmsg m, struct utmpx *u)
+#else
+msg2utmpx(asl_object_t m, struct utmpx *u)
+#endif
{
const char *cp;
SGET(host, ut);
}
-/* fill in a aslmsg from a struct utmpx */
+/* fill in an ASL message from a struct utmpx */
static void
+#if ASL_API_VERSION < 20131108
utmpx2msg(const struct utmpx *u, aslmsg m)
+#else
+utmpx2msg(const struct utmpx *u, asl_object_t m)
+#endif
{
char buf[_UTX_HOSTSIZE + 1]; /* the largest string in struct utmpx */
const char *cp;
"SHUTDOWN_TIME", /* 11 */
};
-/* send a struct utmpx record using asl */
+/* send a struct utmpx record using ASL */
__private_extern__ void
_utmpx_asl(const struct utmpx *u)
{
+#if ASL_API_VERSION < 20131108
aslclient asl = asl_open(NULL, NULL, ASL_OPT_NO_REMOTE); /* could be NULL, but still works */
aslmsg m;
+#else
+ asl_object_t asl = asl_open(NULL, NULL, ASL_OPT_NO_REMOTE);
+ asl_object_t m;
+#endif
char msg[64];
if (u->ut_type == EMPTY)
return;
if ((m = asl_new(ASL_TYPE_MSG)) == NULL) {
+#if ASL_API_VERSION < 20131108
asl_close(asl);
+#else
+ asl_release(asl);
+#endif
return;
}
/*
}
asl_set(m, ASL_KEY_MSG, msg);
asl_send(asl, m);
+#if ASL_API_VERSION < 20131108
asl_free(m);
- if (asl)
- asl_close(asl);
+ asl_close(asl);
+#else
+ asl_release(m);
+ asl_release(asl);
+#endif
}
#define UT_USER (1 << 0)
get_asl,
set_asl
};
+
static struct {
uint64_t start;
int dir;
+#if ASL_API_VERSION < 20131108
asl_search_result_t *res;
+#else
+ asl_object_t res;
+#endif
char *str;
uint32_t len;
char inited;
{
if (wtmp_asl.res != NULL)
{
+#if ASL_API_VERSION < 20131108
aslresponse_free(wtmp_asl.res);
+#else
+ asl_release(wtmp_asl.res);
+#endif
wtmp_asl.res = NULL;
}
static struct utmpx *
get_asl(void)
{
+#if ASL_API_VERSION < 20131108
aslmsg m;
+#else
+ asl_object_t m;
+#endif
static struct utmpx utx;
if (wtmp_asl.inited == 0) set_asl(-1);
if (wtmp_asl.done != 0) return NULL;
+#if ASL_API_VERSION < 20131108
m = aslresponse_next(wtmp_asl.res);
+#else
+ m = asl_next(wtmp_asl.res);
+#endif
if (m == NULL)
{
+#if ASL_API_VERSION < 20131108
aslresponse_free(wtmp_asl.res);
+#else
+ asl_release(wtmp_asl.res);
+#endif
wtmp_asl.res = NULL;
wtmp_asl.done = 1;
return NULL;
static void
set_asl(int forward)
{
+#if ASL_API_VERSION < 20131108
aslmsg q0, q1;
asl_msg_t *m[2];
asl_search_result_t query;
- uint64_t cmax;
- asl_store_t *store;
+ asl_store_t *store = NULL;
uint32_t status;
+ uint64_t cmax;
+#else
+ asl_object_t q0, q1, query;
+ size_t cmax;
+#endif
_set_dir(forward);
if (wtmp_asl.res != NULL)
{
+#if ASL_API_VERSION < 20131108
aslresponse_free(wtmp_asl.res);
+#else
+ asl_release(wtmp_asl.res);
+#endif
wtmp_asl.res = NULL;
}
- store = NULL;
+#if ASL_API_VERSION < 20131108
status = asl_store_open_read(NULL, &store);
if (status != 0) return;
if (store == NULL) return;
+#endif
/*
* Create a search query that matches either UTMPX_FACILITY
* or LASTLOG_FACILITY.
*/
q0 = asl_new(ASL_TYPE_QUERY);
- q1 = asl_new(ASL_TYPE_QUERY);
+ if (q0 == NULL) return;
- if ((q0 == NULL) || (q1 == NULL))
+ asl_set_query(q0, FACILITY, UTMPX_FACILITY, ASL_QUERY_OP_EQUAL);
+
+ q1 = asl_new(ASL_TYPE_QUERY);
+ if (q1 == NULL)
{
- asl_store_close(store);
- if (q0 != NULL) free(q0);
- if (q1 != NULL) free(q1);
+#if ASL_API_VERSION < 20131108
+ asl_free(q0);
+#else
+ asl_release(q0);
+#endif
return;
}
- asl_set_query(q0, FACILITY, UTMPX_FACILITY, ASL_QUERY_OP_EQUAL);
asl_set_query(q1, FACILITY, LASTLOG_FACILITY, ASL_QUERY_OP_EQUAL);
+#if ASL_API_VERSION < 20131108
m[0] = (asl_msg_t *)q0;
m[1] = (asl_msg_t *)q1;
query.count = 2;
query.msg = m;
+#else
+ query = asl_new(ASL_TYPE_LIST);
+ if (query == NULL)
+ {
+ asl_release(q0);
+ asl_release(q1);
+ return;
+ }
+
+ asl_append(query, q0);
+ asl_append(query, q1);
+
+ asl_release(q0);
+ asl_release(q1);
+#endif
cmax = 0;
+#if ASL_API_VERSION < 20131108
asl_store_match_timeout(store, &query, &(wtmp_asl.res), &cmax, wtmp_asl.start, 0, wtmp_asl.dir, ASL_QUERY_TIMEOUT);
asl_store_close(store);
-
- asl_free(q1);
asl_free(q0);
-
+ asl_free(q1);
+#else
+ wtmp_asl.res = asl_match(NULL, query, &cmax, wtmp_asl.start, 0, ASL_QUERY_TIMEOUT, wtmp_asl.dir);
+ asl_release(query);
+#endif
+
if (wtmp_asl.res == NULL) return;
wtmp_asl.inited = 1;