chiark / gitweb /
move selinux noops to udev.h
[elogind.git] / udev / udev.h
1 /*
2  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3  * Copyright (C) 2003-2008 Kay Sievers <kay.sievers@vrfy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef _UDEV_H_
20 #define _UDEV_H_
21
22 #include <sys/types.h>
23 #include <sys/param.h>
24
25 #include "udev_sysdeps.h"
26 #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
27 #include "lib/libudev.h"
28 #include "lib/libudev-private.h"
29 #include "list.h"
30
31 #define ALLOWED_CHARS                           "#+-.:=@_"
32 #define ALLOWED_CHARS_FILE                      ALLOWED_CHARS "/"
33 #define ALLOWED_CHARS_INPUT                     ALLOWED_CHARS_FILE " $%?,"
34
35 #define DEFAULT_PARTITIONS_COUNT                15
36 #define UDEV_EVENT_TIMEOUT                      180
37
38 /* linux/include/linux/kobject.h */
39 #define UEVENT_BUFFER_SIZE                      2048
40 #define UEVENT_NUM_ENVP                         32
41
42 #define UDEV_CTRL_SOCK_PATH                     "@" UDEV_PREFIX "/org/kernel/udev/udevd"
43
44 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
45
46 /* pipes */
47 #define READ_END                                0
48 #define WRITE_END                               1
49
50 struct udev_rules;
51
52 struct sysfs_device {
53         struct list_head node;                  /* for device cache */
54         struct sysfs_device *parent;            /* already cached parent*/
55         char devpath[UTIL_PATH_SIZE];
56         char subsystem[UTIL_NAME_SIZE];
57         char kernel[UTIL_NAME_SIZE];            /* device instance name */
58         char kernel_number[UTIL_NAME_SIZE];
59         char driver[UTIL_NAME_SIZE];
60 };
61
62 struct udevice {
63         struct udev *udev;
64
65         /* device event */
66         struct sysfs_device *dev;               /* points to dev_local by default */
67         struct sysfs_device dev_local;
68         struct sysfs_device *dev_parent;        /* current parent device used for matching */
69         char action[UTIL_NAME_SIZE];
70         char *devpath_old;
71
72         /* node */
73         char name[UTIL_PATH_SIZE];
74         struct list_head symlink_list;
75         int symlink_final;
76         char owner[UTIL_NAME_SIZE];
77         int owner_final;
78         char group[UTIL_NAME_SIZE];
79         int group_final;
80         mode_t mode;
81         int mode_final;
82         dev_t devt;
83
84         /* event processing */
85         struct list_head run_list;
86         int run_final;
87         struct list_head env_list;
88         char tmp_node[UTIL_PATH_SIZE];
89         int partitions;
90         int ignore_device;
91         int ignore_remove;
92         char program_result[UTIL_PATH_SIZE];
93         int link_priority;
94         int event_timeout;
95         int test_run;
96 };
97
98 static inline void logging_init(const char *program_name)
99 {
100         openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
101 }
102
103 static inline void logging_msg(struct udev *udev, int priority,
104                           const char *file, int line, const char *fn,
105                           const char *format, va_list args)
106 {
107         vsyslog(priority, format, args);
108 }
109
110 static inline void logging_close(void)
111 {
112         closelog();
113 }
114
115 /* udev_device.c */
116 extern struct udevice *udev_device_init(struct udev *udev);
117 extern void udev_device_cleanup(struct udevice *udevice);
118 extern dev_t udev_device_get_devt(struct udevice *udevice);
119
120 /* udev_device_event.c */
121 extern int udev_device_event(struct udev_rules *rules, struct udevice *udevice);
122
123 /* udev_sysfs.c */
124 extern int sysfs_init(void);
125 extern void sysfs_cleanup(void);
126 extern void sysfs_device_set_values(struct udev *udev,
127                                     struct sysfs_device *dev, const char *devpath,
128                                     const char *subsystem, const char *driver);
129 extern struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath);
130 extern struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_device *dev);
131 extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, struct sysfs_device *dev, const char *subsystem);
132 extern char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *attr_name);
133 extern int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath, size_t len, const char *subsystem, const char *id);
134
135 /* udev_node.c */
136 extern int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
137 extern void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udev_old);
138 extern int udev_node_add(struct udevice *udevice);
139 extern int udev_node_remove(struct udevice *udevice);
140
141 /* udev_db.c */
142 extern int udev_db_add_device(struct udevice *udevice);
143 extern int udev_db_delete_device(struct udevice *udevice);
144 extern int udev_db_rename(struct udev *udev, const char *devpath_old, const char *devpath);
145 extern int udev_db_get_device(struct udevice *udevice, const char *devpath);
146 extern int udev_db_get_devices_by_name(struct udev *udev, const char *name, struct list_head *name_list);
147
148 /* udev_utils.c */
149 struct name_entry {
150         struct list_head node;
151         char name[UTIL_PATH_SIZE];
152         unsigned int ignore_error:1;
153 };
154 extern struct name_entry *name_list_add(struct udev *udev, struct list_head *name_list, const char *name, int sort);
155 extern struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_list, const char *key, const char *value);
156 extern int name_list_key_remove(struct udev *udev, struct list_head *name_list, const char *key);
157 extern void name_list_cleanup(struct udev *udev, struct list_head *name_list);
158 extern int add_matching_files(struct udev *udev, struct list_head *name_list, const char *dirname, const char *suffix);
159 extern uid_t lookup_user(struct udev *udev, const char *user);
160 extern gid_t lookup_group(struct udev *udev, const char *group);
161
162 /* udev_utils_file.c */
163 extern int create_path(struct udev *udev, const char *path);
164 extern int delete_path(struct udev *udev, const char *path);
165 extern int unlink_secure(struct udev *udev, const char *filename);
166 extern int file_map(const char *filename, char **buf, size_t *bufsize);
167 extern void file_unmap(void *buf, size_t bufsize);
168 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
169
170 /* udev_selinux */
171 #ifndef USE_SELINUX
172 static inline void selinux_init(struct udev *udev) {}
173 static inline void selinux_exit(struct udev *udev) {}
174 static inline void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode) {}
175 static inline void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode) {}
176 static inline void udev_selinux_resetfscreatecon(struct udev *udev) {}
177 #else
178 extern void selinux_init(struct udev *udev);
179 extern void selinux_exit(struct udev *udev);
180 extern void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode);
181 extern void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode);
182 extern void udev_selinux_resetfscreatecon(struct udev *udev);
183 #endif
184
185 /* udevadm commands */
186 extern int udevadm_monitor(struct udev *udev, int argc, char *argv[]);
187 extern int udevadm_info(struct udev *udev, int argc, char *argv[]);
188 extern int udevadm_control(struct udev *udev, int argc, char *argv[]);
189 extern int udevadm_trigger(struct udev *udev, int argc, char *argv[]);
190 extern int udevadm_settle(struct udev *udev, int argc, char *argv[]);
191 extern int udevadm_test(struct udev *udev, int argc, char *argv[]);
192
193 #endif