* Authorization scopes.
*/
-lck_grp_t *kauth_lck_grp;
-static lck_mtx_t *kauth_scope_mtx;
-#define KAUTH_SCOPELOCK() lck_mtx_lock(kauth_scope_mtx);
-#define KAUTH_SCOPEUNLOCK() lck_mtx_unlock(kauth_scope_mtx);
+LCK_GRP_DECLARE(kauth_lck_grp, "kauth");
+static LCK_MTX_DECLARE(kauth_scope_mtx, &kauth_lck_grp);
+#define KAUTH_SCOPELOCK() lck_mtx_lock(&kauth_scope_mtx);
+#define KAUTH_SCOPEUNLOCK() lck_mtx_unlock(&kauth_scope_mtx);
/*
* We support listeners for scopes that have not been registered yet.
};
typedef struct kauth_local_listener *kauth_local_listener_t;
-static TAILQ_HEAD(, kauth_listener) kauth_dangling_listeners;
+static TAILQ_HEAD(, kauth_listener) kauth_dangling_listeners =
+ TAILQ_HEAD_INITIALIZER(kauth_dangling_listeners);
/*
* Scope listeners need to be reworked to be dynamic.
/* values for kauth_scope.ks_flags */
#define KS_F_HAS_LISTENERS (1 << 0)
-static TAILQ_HEAD(, kauth_scope) kauth_scopes;
+static TAILQ_HEAD(, kauth_scope) kauth_scopes = TAILQ_HEAD_INITIALIZER(kauth_scopes);
static int kauth_add_callback_to_scope(kauth_scope_t sp, kauth_listener_t klp);
static void kauth_scope_init(void);
void
kauth_init(void)
{
- lck_grp_attr_t *grp_attributes;
-
- TAILQ_INIT(&kauth_scopes);
- TAILQ_INIT(&kauth_dangling_listeners);
-
- /* set up our lock group */
- grp_attributes = lck_grp_attr_alloc_init();
- kauth_lck_grp = lck_grp_alloc_init("kauth", grp_attributes);
- lck_grp_attr_free(grp_attributes);
-
/* bring up kauth subsystem components */
kauth_cred_init();
-#if CONFIG_EXT_RESOLVER
- kauth_identity_init();
- kauth_groups_init();
-#endif
kauth_scope_init();
-#if CONFIG_EXT_RESOLVER
- kauth_resolver_init();
-#endif
- /* can't alloc locks after this */
- lck_grp_free(kauth_lck_grp);
- kauth_lck_grp = NULL;
}
static void
kauth_scope_init(void)
{
- kauth_scope_mtx = lck_mtx_alloc_init(kauth_lck_grp, 0 /*LCK_ATTR_NULL*/);
kauth_scope_process = kauth_register_scope(KAUTH_SCOPE_PROCESS, kauth_authorize_process_callback, NULL);
kauth_scope_generic = kauth_register_scope(KAUTH_SCOPE_GENERIC, kauth_authorize_generic_callback, NULL);
kauth_scope_fileop = kauth_register_scope(KAUTH_SCOPE_FILEOP, NULL, NULL);
/*
* Allocate and populate the scope structure.
*/
- MALLOC(sp, kauth_scope_t, sizeof(*sp), M_KAUTH, M_WAITOK | M_ZERO);
+ sp = kheap_alloc(KM_KAUTH, sizeof(*sp), Z_WAITOK | Z_ZERO);
if (sp == NULL) {
return NULL;
}
/*
* Allocate and populate the listener structure.
*/
- MALLOC(lsp, kauth_listener_t, sizeof(*lsp), M_KAUTH, M_WAITOK);
+ lsp = kheap_alloc(KM_KAUTH, sizeof(*lsp), Z_WAITOK);
if (lsp == NULL) {
return NULL;
}
if (strncmp(tsp->ks_identifier, identifier,
strlen(tsp->ks_identifier) + 1) == 0) {
KAUTH_SCOPEUNLOCK();
- FREE(sp, M_KAUTH);
+ kheap_free(KM_KAUTH, sp, sizeof(struct kauth_scope));
return NULL;
}
}
}
}
KAUTH_SCOPEUNLOCK();
- FREE(scope, M_KAUTH);
+ kheap_free(KM_KAUTH, scope, sizeof(struct kauth_scope));
return;
}
}
/* table already full */
KAUTH_SCOPEUNLOCK();
- FREE(klp, M_KAUTH);
+ kheap_free(KM_KAUTH, klp, sizeof(struct kauth_listener));
return NULL;
}
}
sp->ks_flags &= ~KS_F_HAS_LISTENERS;
}
KAUTH_SCOPEUNLOCK();
- FREE(listener, M_KAUTH);
+ kheap_free(KM_KAUTH, listener, sizeof(struct kauth_listener));
return;
}
}
if (klp == listener) {
TAILQ_REMOVE(&kauth_dangling_listeners, klp, kl_link);
KAUTH_SCOPEUNLOCK();
- FREE(listener, M_KAUTH);
+ kheap_free(KM_KAUTH, listener, sizeof(struct kauth_listener));
return;
}
}
return NULL;
}
- MALLOC(fsp, kauth_filesec_t, KAUTH_FILESEC_SIZE(count), M_KAUTH, M_WAITOK);
+ fsp = kheap_alloc(KM_KAUTH, KAUTH_FILESEC_SIZE(count), Z_WAITOK);
if (fsp != NULL) {
fsp->fsec_magic = KAUTH_FILESEC_MAGIC;
fsp->fsec_owner = kauth_null_guid;
panic("freeing KAUTH_FILESEC_WANTED");
}
#endif
- FREE(fsp, M_KAUTH);
+ kheap_free_addr(KM_KAUTH, fsp);
}
/*
return NULL;
}
- MALLOC(aclp, kauth_acl_t, KAUTH_ACL_SIZE(count), M_KAUTH, M_WAITOK);
+ aclp = kheap_alloc(KM_KAUTH, KAUTH_ACL_SIZE(count), Z_WAITOK);
if (aclp != NULL) {
aclp->acl_entrycount = 0;
aclp->acl_flags = 0;