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