xref: /freebsd/usr.sbin/ypldap/ypldap.h (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
19e7c127fSCraig Rodrigues /*	$OpenBSD: ypldap.h,v 1.16 2015/01/16 06:40:22 deraadt Exp $ */
29e7c127fSCraig Rodrigues 
39e7c127fSCraig Rodrigues /*
49e7c127fSCraig Rodrigues  * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
59e7c127fSCraig Rodrigues  *
69e7c127fSCraig Rodrigues  * Permission to use, copy, modify, and distribute this software for any
79e7c127fSCraig Rodrigues  * purpose with or without fee is hereby granted, provided that the above
89e7c127fSCraig Rodrigues  * copyright notice and this permission notice appear in all copies.
99e7c127fSCraig Rodrigues  *
109e7c127fSCraig Rodrigues  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
119e7c127fSCraig Rodrigues  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
129e7c127fSCraig Rodrigues  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
139e7c127fSCraig Rodrigues  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
149e7c127fSCraig Rodrigues  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
159e7c127fSCraig Rodrigues  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
169e7c127fSCraig Rodrigues  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
179e7c127fSCraig Rodrigues  */
189e7c127fSCraig Rodrigues 
199e7c127fSCraig Rodrigues #include <imsg.h>
209e7c127fSCraig Rodrigues 
219e7c127fSCraig Rodrigues #define YPLDAP_USER		"_ypldap"
229e7c127fSCraig Rodrigues #define YPLDAP_CONF_FILE	"/etc/ypldap.conf"
239e7c127fSCraig Rodrigues #define DEFAULT_INTERVAL	600
249e7c127fSCraig Rodrigues #define LINE_WIDTH		1024
259e7c127fSCraig Rodrigues #define FILTER_WIDTH		128
269e7c127fSCraig Rodrigues #define ATTR_WIDTH		32
279e7c127fSCraig Rodrigues 
289e7c127fSCraig Rodrigues #define        MAX_SERVERS_DNS                 8
299e7c127fSCraig Rodrigues 
309e7c127fSCraig Rodrigues enum imsg_type {
319e7c127fSCraig Rodrigues 	IMSG_NONE,
329e7c127fSCraig Rodrigues 	IMSG_CONF_START,
339e7c127fSCraig Rodrigues 	IMSG_CONF_IDM,
349e7c127fSCraig Rodrigues 	IMSG_CONF_END,
359e7c127fSCraig Rodrigues 	IMSG_START_UPDATE,
369e7c127fSCraig Rodrigues 	IMSG_END_UPDATE,
379e7c127fSCraig Rodrigues 	IMSG_TRASH_UPDATE,
389e7c127fSCraig Rodrigues 	IMSG_PW_ENTRY,
399e7c127fSCraig Rodrigues 	IMSG_GRP_ENTRY,
409e7c127fSCraig Rodrigues 	IMSG_HOST_DNS
419e7c127fSCraig Rodrigues };
429e7c127fSCraig Rodrigues 
439e7c127fSCraig Rodrigues struct ypldap_addr {
44eaf209deSMarcelo Araujo 	TAILQ_ENTRY(ypldap_addr)	next;
459e7c127fSCraig Rodrigues 	struct sockaddr_storage         ss;
469e7c127fSCraig Rodrigues };
47eaf209deSMarcelo Araujo TAILQ_HEAD(ypldap_addr_list, ypldap_addr);
489e7c127fSCraig Rodrigues 
493a166b33SKyle Evans enum ypldap_process_type {
509e7c127fSCraig Rodrigues 	PROC_MAIN,
519e7c127fSCraig Rodrigues 	PROC_CLIENT
523a166b33SKyle Evans };
533a166b33SKyle Evans extern enum ypldap_process_type		ypldap_process;
549e7c127fSCraig Rodrigues 
559e7c127fSCraig Rodrigues struct userent {
569e7c127fSCraig Rodrigues 	RB_ENTRY(userent)		 ue_name_node;
579e7c127fSCraig Rodrigues 	RB_ENTRY(userent)		 ue_uid_node;
589e7c127fSCraig Rodrigues 	uid_t				 ue_uid;
599e7c127fSCraig Rodrigues 	char				*ue_line;
609e7c127fSCraig Rodrigues 	char				*ue_netid_line;
619e7c127fSCraig Rodrigues 	gid_t				 ue_gid;
629e7c127fSCraig Rodrigues };
639e7c127fSCraig Rodrigues 
649e7c127fSCraig Rodrigues struct groupent {
659e7c127fSCraig Rodrigues 	RB_ENTRY(groupent)		 ge_name_node;
669e7c127fSCraig Rodrigues 	RB_ENTRY(groupent)		 ge_gid_node;
679e7c127fSCraig Rodrigues 	gid_t				 ge_gid;
689e7c127fSCraig Rodrigues 	char				*ge_line;
699e7c127fSCraig Rodrigues };
709e7c127fSCraig Rodrigues 
719e7c127fSCraig Rodrigues enum client_state {
729e7c127fSCraig Rodrigues         STATE_NONE,
739e7c127fSCraig Rodrigues         STATE_DNS_INPROGRESS,
749e7c127fSCraig Rodrigues         STATE_DNS_TEMPFAIL,
759e7c127fSCraig Rodrigues         STATE_DNS_DONE,
769e7c127fSCraig Rodrigues 	STATE_LDAP_FAIL,
779e7c127fSCraig Rodrigues 	STATE_LDAP_DONE
789e7c127fSCraig Rodrigues };
799e7c127fSCraig Rodrigues 
809e7c127fSCraig Rodrigues /*
819e7c127fSCraig Rodrigues  * beck, djm, dlg: pay attention to the struct name
829e7c127fSCraig Rodrigues  */
839e7c127fSCraig Rodrigues struct idm {
849e7c127fSCraig Rodrigues 	TAILQ_ENTRY(idm)		 idm_entry;
859e7c127fSCraig Rodrigues 	u_int32_t                        idm_id;
86cc7c29bfSCraig Rodrigues 	char				 idm_name[MAXHOSTNAMELEN];
879e7c127fSCraig Rodrigues #define F_SSL				 0x00100000
889e7c127fSCraig Rodrigues #define F_CONFIGURING			 0x00200000
899e7c127fSCraig Rodrigues #define F_NEEDAUTH			 0x00400000
909e7c127fSCraig Rodrigues #define F_FIXED_ATTR(n)			 (1<<n)
919e7c127fSCraig Rodrigues #define F_LIST(n)                        (1<<n)
929e7c127fSCraig Rodrigues 	enum client_state		 idm_state;
939e7c127fSCraig Rodrigues 	u_int32_t			 idm_flags; /* lower 20 reserved */
949e7c127fSCraig Rodrigues 	u_int32_t			 idm_list;
95eaf209deSMarcelo Araujo 	struct ypldap_addr_list		 idm_addr;
969e7c127fSCraig Rodrigues 	in_port_t			 idm_port;
979e7c127fSCraig Rodrigues 	char				 idm_binddn[LINE_WIDTH];
989e7c127fSCraig Rodrigues 	char				 idm_bindcred[LINE_WIDTH];
999e7c127fSCraig Rodrigues 	char				 idm_basedn[LINE_WIDTH];
1009e7c127fSCraig Rodrigues 	char				 idm_groupdn[LINE_WIDTH];
1019e7c127fSCraig Rodrigues #define FILTER_USER			 1
1029e7c127fSCraig Rodrigues #define FILTER_GROUP			 0
1039e7c127fSCraig Rodrigues 	char				 idm_filters[2][FILTER_WIDTH];
1049e7c127fSCraig Rodrigues #define ATTR_NAME			 0
1059e7c127fSCraig Rodrigues #define ATTR_PASSWD			 1
1069e7c127fSCraig Rodrigues #define ATTR_UID			 2
1079e7c127fSCraig Rodrigues #define ATTR_GID			 3
1089e7c127fSCraig Rodrigues #define ATTR_CLASS			 4
1099e7c127fSCraig Rodrigues #define ATTR_CHANGE			 5
1109e7c127fSCraig Rodrigues #define ATTR_EXPIRE			 6
1119e7c127fSCraig Rodrigues #define ATTR_GECOS			 7
1129e7c127fSCraig Rodrigues #define ATTR_DIR			 8
1139e7c127fSCraig Rodrigues #define ATTR_SHELL			 9
1149e7c127fSCraig Rodrigues #define ATTR_GR_NAME			 10
1159e7c127fSCraig Rodrigues #define ATTR_GR_PASSWD			 11
1169e7c127fSCraig Rodrigues #define ATTR_GR_GID			 12
1179e7c127fSCraig Rodrigues #define ATTR_GR_MEMBERS			 13
1189e7c127fSCraig Rodrigues #define ATTR_MAX			 10
1199e7c127fSCraig Rodrigues #define ATTR_GR_MIN			 10
1209e7c127fSCraig Rodrigues #define ATTR_GR_MAX			 14
1219e7c127fSCraig Rodrigues 	char				 idm_attrs[14][ATTR_WIDTH];
1229e7c127fSCraig Rodrigues 	struct env			*idm_env;
1239e7c127fSCraig Rodrigues 	struct event			 idm_ev;
1249e7c127fSCraig Rodrigues #ifdef SSL
1259e7c127fSCraig Rodrigues 	struct ssl			*idm_ssl;
1269e7c127fSCraig Rodrigues #endif
1279e7c127fSCraig Rodrigues };
1289e7c127fSCraig Rodrigues 
1299e7c127fSCraig Rodrigues struct idm_req {
1309e7c127fSCraig Rodrigues 	union {
1319e7c127fSCraig Rodrigues 		uid_t			 ik_uid;
1329e7c127fSCraig Rodrigues 		uid_t			 ik_gid;
1339e7c127fSCraig Rodrigues 	}				 ir_key;
1349e7c127fSCraig Rodrigues 	char				 ir_line[LINE_WIDTH];
1359e7c127fSCraig Rodrigues };
1369e7c127fSCraig Rodrigues 
1379e7c127fSCraig Rodrigues struct imsgev {
1389e7c127fSCraig Rodrigues 	struct imsgbuf		 ibuf;
1399e7c127fSCraig Rodrigues 	void			(*handler)(int, short, void *);
1409e7c127fSCraig Rodrigues 	struct event		 ev;
1419e7c127fSCraig Rodrigues 	void			*data;
1429e7c127fSCraig Rodrigues 	short			 events;
1439e7c127fSCraig Rodrigues };
1449e7c127fSCraig Rodrigues 
1459e7c127fSCraig Rodrigues struct env {
1469e7c127fSCraig Rodrigues #define YPLDAP_OPT_VERBOSE		 0x01
1479e7c127fSCraig Rodrigues #define YPLDAP_OPT_NOACTION		 0x02
1489e7c127fSCraig Rodrigues 	u_int8_t			 sc_opts;
1499e7c127fSCraig Rodrigues #define YPMAP_PASSWD_BYNAME		 0x00000001
1509e7c127fSCraig Rodrigues #define YPMAP_PASSWD_BYUID		 0x00000002
1519e7c127fSCraig Rodrigues #define YPMAP_MASTER_PASSWD_BYNAME	 0x00000004
1529e7c127fSCraig Rodrigues #define YPMAP_MASTER_PASSWD_BYUID	 0x00000008
1539e7c127fSCraig Rodrigues #define YPMAP_GROUP_BYNAME		 0x00000010
1549e7c127fSCraig Rodrigues #define YPMAP_GROUP_BYGID		 0x00000020
1559e7c127fSCraig Rodrigues #define YPMAP_NETID_BYNAME		 0x00000040
1569e7c127fSCraig Rodrigues 	u_int32_t			 sc_flags;
1579e7c127fSCraig Rodrigues 
1589e7c127fSCraig Rodrigues 	u_int32_t			 sc_maxid;
1599e7c127fSCraig Rodrigues 
160cc7c29bfSCraig Rodrigues 	char				 sc_domainname[MAXHOSTNAMELEN];
1619e7c127fSCraig Rodrigues 	struct timeval			 sc_conf_tv;
1629e7c127fSCraig Rodrigues 	struct event			 sc_conf_ev;
1639e7c127fSCraig Rodrigues 	TAILQ_HEAD(idm_list, idm)	 sc_idms;
1649e7c127fSCraig Rodrigues 	struct imsgev			*sc_iev;
1659e7c127fSCraig Rodrigues 	struct imsgev			*sc_iev_dns;
1669e7c127fSCraig Rodrigues 
1679e7c127fSCraig Rodrigues 	RB_HEAD(user_name_tree,userent)	 *sc_user_names;
1689e7c127fSCraig Rodrigues 	RB_HEAD(user_uid_tree,userent)	 sc_user_uids;
1699e7c127fSCraig Rodrigues 	RB_HEAD(group_name_tree,groupent)*sc_group_names;
1709e7c127fSCraig Rodrigues 	RB_HEAD(group_gid_tree,groupent) sc_group_gids;
1719e7c127fSCraig Rodrigues 	struct user_name_tree		 *sc_user_names_t;
1729e7c127fSCraig Rodrigues 	struct group_name_tree		 *sc_group_names_t;
1739e7c127fSCraig Rodrigues 	size_t				 sc_user_line_len;
1749e7c127fSCraig Rodrigues 	size_t				 sc_group_line_len;
1759e7c127fSCraig Rodrigues 	char				*sc_user_lines;
1769e7c127fSCraig Rodrigues 	char				*sc_group_lines;
1779e7c127fSCraig Rodrigues 
1789e7c127fSCraig Rodrigues 	struct yp_data			*sc_yp;
1799e7c127fSCraig Rodrigues 
1809e7c127fSCraig Rodrigues 	int				 update_trashed;
1819e7c127fSCraig Rodrigues };
1829e7c127fSCraig Rodrigues 
1839e7c127fSCraig Rodrigues /* log.c */
1849e7c127fSCraig Rodrigues void		 log_init(int);
1859e7c127fSCraig Rodrigues void		 log_warn(const char *, ...);
1869e7c127fSCraig Rodrigues void		 log_warnx(const char *, ...);
1879e7c127fSCraig Rodrigues void		 log_info(const char *, ...);
1889e7c127fSCraig Rodrigues void		 log_debug(const char *, ...);
1899e7c127fSCraig Rodrigues void		 logit(int, const char *, ...);
1909e7c127fSCraig Rodrigues void		 vlog(int, const char *, va_list);
191ab905b04SCraig Rodrigues __dead2 void	 fatal(const char *);
192ab905b04SCraig Rodrigues __dead2 void	 fatalx(const char *);
1939e7c127fSCraig Rodrigues 
1949e7c127fSCraig Rodrigues /* parse.y */
1959e7c127fSCraig Rodrigues int		 parse_config(struct env *, const char *, int);
1969e7c127fSCraig Rodrigues int		 cmdline_symset(char *);
1979e7c127fSCraig Rodrigues 
1989e7c127fSCraig Rodrigues /* ldapclient.c */
199*c41b1618SJohn Baldwin pid_t		 ldapclient(int [2]);
2009e7c127fSCraig Rodrigues 
2019e7c127fSCraig Rodrigues /* ypldap.c */
2029e7c127fSCraig Rodrigues void		 purge_config(struct env *);
2039e7c127fSCraig Rodrigues void		 imsg_event_add(struct imsgev *);
2049e7c127fSCraig Rodrigues int	 	 imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t,
2059e7c127fSCraig Rodrigues 		    pid_t, int, void *, u_int16_t);
2069e7c127fSCraig Rodrigues 
2079e7c127fSCraig Rodrigues /* entries.c */
2089e7c127fSCraig Rodrigues void		 flatten_entries(struct env *);
2099e7c127fSCraig Rodrigues int		 userent_name_cmp(struct userent *, struct userent *);
2109e7c127fSCraig Rodrigues int		 userent_uid_cmp(struct userent *, struct userent *);
2119e7c127fSCraig Rodrigues int		 groupent_name_cmp(struct groupent *, struct groupent *);
2129e7c127fSCraig Rodrigues int		 groupent_gid_cmp(struct groupent *, struct groupent *);
2139e7c127fSCraig Rodrigues RB_PROTOTYPE(	 user_name_tree, userent, ue_name_node, userent_name_cmp);
2149e7c127fSCraig Rodrigues RB_PROTOTYPE(	 user_uid_tree, userent, ue_uid_node, userent_uid_cmp);
2159e7c127fSCraig Rodrigues RB_PROTOTYPE(	 group_name_tree, groupent, ge_name_node, groupent_name_cmp);
2169e7c127fSCraig Rodrigues RB_PROTOTYPE(	 group_gid_tree, groupent, ge_gid_node, groupent_gid_cmp);
2179e7c127fSCraig Rodrigues 
2189e7c127fSCraig Rodrigues /* yp.c */
2199e7c127fSCraig Rodrigues void		 yp_init(struct env *);
2209e7c127fSCraig Rodrigues void		 yp_enable_events(void);
2219e7c127fSCraig Rodrigues 
2229e7c127fSCraig Rodrigues /* ypldap_dns.c */
2239e7c127fSCraig Rodrigues pid_t		 ypldap_dns(int[2], struct passwd *);
224