]> git.saurik.com Git - apple/libc.git/blobdiff - gen/utmpx-darwin.c
Libc-1044.1.2.tar.gz
[apple/libc.git] / gen / utmpx-darwin.c
index ac8b96d5557755c983ef5d7a220759607dfc85c0..485fa5dd158899d195f93d74bbe86e0ae4e9c5ef 100644 (file)
@@ -41,8 +41,6 @@
 #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;
 
@@ -140,51 +149,86 @@ getlastlogx(uid_t uid, struct lastlogx *lx)
 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;
        }
 
@@ -192,13 +236,21 @@ getlastlogxbyname(const char *user, struct lastlogx *lx)
        {
                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;
@@ -210,9 +262,13 @@ getlastlogxbyname(const char *user, struct lastlogx *lx)
 #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;
 
@@ -223,9 +279,13 @@ msg2lastlogx(const aslmsg m, struct lastlogx *u)
        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;
 
@@ -240,9 +300,13 @@ msg2utmpx(const aslmsg m, struct utmpx *u)
        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;
@@ -291,18 +355,27 @@ static const char *utmpx_types[] = {
        "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;
        }
        /*
@@ -343,9 +416,13 @@ _utmpx_asl(const struct utmpx *u)
        }
        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)
@@ -479,10 +556,15 @@ static struct {
        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;
@@ -575,7 +657,11 @@ end_asl(void)
 {
        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;
        }
 
@@ -599,16 +685,28 @@ end_file(void)
 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;
@@ -713,12 +811,17 @@ _set_dir(int forward)
 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);
 
@@ -727,46 +830,75 @@ set_asl(int 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;