udev-acl.c revision af23b83ea714756aa4bfed7f7501739c69428e40
/*
* Copyright (C) 2009 Kay Sievers <kay.sievers@vrfy.org>
*
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details:
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <glib.h>
#include <libudev.h>
static int debug;
{
int get;
acl_entry_t e;
int ret;
/* read current record */
if (!acl)
return -1;
/* locate ACL_USER entry for uid */
while (get == 1) {
acl_tag_t t;
acl_get_tag_type(e, &t);
if (t == ACL_USER) {
uid_t *u;
u = (uid_t*)acl_get_qualifier(e);
if (u == NULL) {
ret = -1;
goto out;
}
if (*u == uid) {
entry = e;
acl_free(u);
break;
}
acl_free(u);
}
}
/* remove ACL_USER entry for uid */
if (!add) {
ret = 0;
goto out;
}
goto update;
}
/* create ACL_USER entry for uid */
if (ret != 0)
goto out;
}
/* add permissions for uid */
/* update record */
if (debug)
acl_calc_mask(&acl);
if (ret != 0)
goto out;
out:
return ret;
}
/* check if a given uid is listed */
{
GSList *l;
return 1;
return 0;
}
/* return list of current uids of local active sessions */
{
keyfile = g_key_file_new();
int i;
uid_t u;
continue;
continue;
continue;
continue;
if (u > 0 && !uid_in_list(list, u))
}
}
}
return list;
}
/* ConsoleKit calls us with special variables */
{
int a;
uid_t u;
const char *s;
const char *session;
return -1;
s = getenv("CK_SESSION_IS_LOCAL");
if (s == NULL)
return -1;
if (strcmp(s, "true") != 0)
return 0;
s = getenv("CK_SESSION_IS_ACTIVE");
if (s == NULL)
return -1;
if (strcmp(s, "true") == 0)
a = 1;
else
a = 0;
return -1;
s = getenv("CK_SESSION_USER_UID");
if (s == NULL)
return -1;
if (u == 0)
return 0;
*own_session = session;
*uid = u;
*add = a;
return 0;
}
/* add or remove a ACL for a given uid from all matching devices */
{
struct udev_enumerate *enumerate;
struct udev_list_entry *list_entry;
/* iterate over all devices tagged with ACL_SET */
struct udev_device *device;
const char *node;
continue;
continue;
}
}
{
{}
};
int add = -1;
const char* own_session = NULL;
int rc = 0;
/* valgrind is more important to us than a slice allocator */
while (1) {
int option;
if (option == -1)
break;
switch (option) {
case 'a':
add = 1;
add = 0;
else
goto out;
break;
case 'D':
break;
case 'u':
break;
case 'd':
debug = 1;
break;
case 'h':
printf("Usage: udev-acl --action=ACTION [--device=DEVICEFILE] [--user=UID]\n\n");
default:
goto out;
}
}
if (add < 0) {
rc = 2;
goto out;
}
rc = 3;
goto out;
}
if (uid != 0) {
if (add) {
/* Add ACL for given uid to all matching devices. */
} else {
/*
* Remove ACL for given uid from all matching devices
* when there is currently no local active session.
*/
apply_acl_to_devices(uid, 0);
}
/*
* Add ACLs for all current session uids to a given device.
*
* Or remove ACLs for uids which do not have any current local
* active session. Remove is not really interesting, because in
* most cases the device node is removed anyway.
*/
GSList *l;
uid_t u;
u = GPOINTER_TO_UINT(l->data);
}
} else {
rc = 3;
}
out:
return rc;
}