xref: /freebsd/usr.sbin/ypldap/ypldap.h (revision 1f4bcc459a76b7aa664f3fd557684cd0ba6da352)
1 /*	$OpenBSD: ypldap.h,v 1.16 2015/01/16 06:40:22 deraadt Exp $ */
2 /*	$FreeBSD$ */
3 
4 /*
5  * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <imsg.h>
21 
22 #define YPLDAP_USER		"_ypldap"
23 #define YPLDAP_CONF_FILE	"/etc/ypldap.conf"
24 #define DEFAULT_INTERVAL	600
25 #define LINE_WIDTH		1024
26 #define FILTER_WIDTH		128
27 #define ATTR_WIDTH		32
28 
29 #define        MAX_SERVERS_DNS                 8
30 
31 enum imsg_type {
32 	IMSG_NONE,
33 	IMSG_CONF_START,
34 	IMSG_CONF_IDM,
35 	IMSG_CONF_END,
36 	IMSG_START_UPDATE,
37 	IMSG_END_UPDATE,
38 	IMSG_TRASH_UPDATE,
39 	IMSG_PW_ENTRY,
40 	IMSG_GRP_ENTRY,
41 	IMSG_HOST_DNS
42 };
43 
44 struct ypldap_addr {
45 	struct ypldap_addr              *next;
46 	struct sockaddr_storage          ss;
47 };
48 
49 enum {
50 	PROC_MAIN,
51 	PROC_CLIENT
52 } ypldap_process;
53 
54 struct userent {
55 	RB_ENTRY(userent)		 ue_name_node;
56 	RB_ENTRY(userent)		 ue_uid_node;
57 	uid_t				 ue_uid;
58 	char				*ue_line;
59 	char				*ue_netid_line;
60 	gid_t				 ue_gid;
61 };
62 
63 struct groupent {
64 	RB_ENTRY(groupent)		 ge_name_node;
65 	RB_ENTRY(groupent)		 ge_gid_node;
66 	gid_t				 ge_gid;
67 	char				*ge_line;
68 };
69 
70 enum client_state {
71         STATE_NONE,
72         STATE_DNS_INPROGRESS,
73         STATE_DNS_TEMPFAIL,
74         STATE_DNS_DONE,
75 	STATE_LDAP_FAIL,
76 	STATE_LDAP_DONE
77 };
78 
79 /*
80  * beck, djm, dlg: pay attention to the struct name
81  */
82 struct idm {
83 	TAILQ_ENTRY(idm)		 idm_entry;
84 	u_int32_t                        idm_id;
85 	char				 idm_name[MAXHOSTNAMELEN];
86 #define F_SSL				 0x00100000
87 #define F_CONFIGURING			 0x00200000
88 #define F_NEEDAUTH			 0x00400000
89 #define F_FIXED_ATTR(n)			 (1<<n)
90 #define F_LIST(n)                        (1<<n)
91 	enum client_state		 idm_state;
92 	u_int32_t			 idm_flags; /* lower 20 reserved */
93 	u_int32_t			 idm_list;
94 	struct ypldap_addr		*idm_addr;
95 	in_port_t			 idm_port;
96 	char				 idm_binddn[LINE_WIDTH];
97 	char				 idm_bindcred[LINE_WIDTH];
98 	char				 idm_basedn[LINE_WIDTH];
99 	char				 idm_groupdn[LINE_WIDTH];
100 #define FILTER_USER			 1
101 #define FILTER_GROUP			 0
102 	char				 idm_filters[2][FILTER_WIDTH];
103 #define ATTR_NAME			 0
104 #define ATTR_PASSWD			 1
105 #define ATTR_UID			 2
106 #define ATTR_GID			 3
107 #define ATTR_CLASS			 4
108 #define ATTR_CHANGE			 5
109 #define ATTR_EXPIRE			 6
110 #define ATTR_GECOS			 7
111 #define ATTR_DIR			 8
112 #define ATTR_SHELL			 9
113 #define ATTR_GR_NAME			 10
114 #define ATTR_GR_PASSWD			 11
115 #define ATTR_GR_GID			 12
116 #define ATTR_GR_MEMBERS			 13
117 #define ATTR_MAX			 10
118 #define ATTR_GR_MIN			 10
119 #define ATTR_GR_MAX			 14
120 	char				 idm_attrs[14][ATTR_WIDTH];
121 	struct env			*idm_env;
122 	struct event			 idm_ev;
123 #ifdef SSL
124 	struct ssl			*idm_ssl;
125 #endif
126 };
127 
128 struct idm_req {
129 	union {
130 		uid_t			 ik_uid;
131 		uid_t			 ik_gid;
132 	}				 ir_key;
133 	char				 ir_line[LINE_WIDTH];
134 };
135 
136 struct imsgev {
137 	struct imsgbuf		 ibuf;
138 	void			(*handler)(int, short, void *);
139 	struct event		 ev;
140 	void			*data;
141 	short			 events;
142 };
143 
144 struct env {
145 #define YPLDAP_OPT_VERBOSE		 0x01
146 #define YPLDAP_OPT_NOACTION		 0x02
147 	u_int8_t			 sc_opts;
148 #define YPMAP_PASSWD_BYNAME		 0x00000001
149 #define YPMAP_PASSWD_BYUID		 0x00000002
150 #define YPMAP_MASTER_PASSWD_BYNAME	 0x00000004
151 #define YPMAP_MASTER_PASSWD_BYUID	 0x00000008
152 #define YPMAP_GROUP_BYNAME		 0x00000010
153 #define YPMAP_GROUP_BYGID		 0x00000020
154 #define YPMAP_NETID_BYNAME		 0x00000040
155 	u_int32_t			 sc_flags;
156 
157 	u_int32_t			 sc_maxid;
158 
159 	char				 sc_domainname[MAXHOSTNAMELEN];
160 	struct timeval			 sc_conf_tv;
161 	struct event			 sc_conf_ev;
162 	TAILQ_HEAD(idm_list, idm)	 sc_idms;
163 	struct imsgev			*sc_iev;
164 	struct imsgev			*sc_iev_dns;
165 
166 	RB_HEAD(user_name_tree,userent)	 *sc_user_names;
167 	RB_HEAD(user_uid_tree,userent)	 sc_user_uids;
168 	RB_HEAD(group_name_tree,groupent)*sc_group_names;
169 	RB_HEAD(group_gid_tree,groupent) sc_group_gids;
170 	struct user_name_tree		 *sc_user_names_t;
171 	struct group_name_tree		 *sc_group_names_t;
172 	size_t				 sc_user_line_len;
173 	size_t				 sc_group_line_len;
174 	char				*sc_user_lines;
175 	char				*sc_group_lines;
176 
177 	struct yp_data			*sc_yp;
178 
179 	int				 update_trashed;
180 };
181 
182 /* log.c */
183 void		 log_init(int);
184 void		 log_warn(const char *, ...);
185 void		 log_warnx(const char *, ...);
186 void		 log_info(const char *, ...);
187 void		 log_debug(const char *, ...);
188 void		 logit(int, const char *, ...);
189 void		 vlog(int, const char *, va_list);
190 __dead2 void	 fatal(const char *);
191 __dead2 void	 fatalx(const char *);
192 
193 /* parse.y */
194 int		 parse_config(struct env *, const char *, int);
195 int		 cmdline_symset(char *);
196 
197 /* ldapclient.c */
198 pid_t		 ldapclient(int []);
199 
200 /* ypldap.c */
201 void		 purge_config(struct env *);
202 void		 imsg_event_add(struct imsgev *);
203 int	 	 imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t,
204 		    pid_t, int, void *, u_int16_t);
205 
206 /* entries.c */
207 void		 flatten_entries(struct env *);
208 int		 userent_name_cmp(struct userent *, struct userent *);
209 int		 userent_uid_cmp(struct userent *, struct userent *);
210 int		 groupent_name_cmp(struct groupent *, struct groupent *);
211 int		 groupent_gid_cmp(struct groupent *, struct groupent *);
212 RB_PROTOTYPE(	 user_name_tree, userent, ue_name_node, userent_name_cmp);
213 RB_PROTOTYPE(	 user_uid_tree, userent, ue_uid_node, userent_uid_cmp);
214 RB_PROTOTYPE(	 group_name_tree, groupent, ge_name_node, groupent_name_cmp);
215 RB_PROTOTYPE(	 group_gid_tree, groupent, ge_gid_node, groupent_gid_cmp);
216 
217 /* yp.c */
218 void		 yp_init(struct env *);
219 void		 yp_enable_events(void);
220 
221 /* ypldap_dns.c */
222 pid_t		 ypldap_dns(int[2], struct passwd *);
223