1 /*
2     ldapdiff
3     Copyright (C) 2000-2008 Thomas.Reith@rhoen.de
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 3 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 #define LDAPDIFFCONF  "ldapdiff.conf"
20 #define SYSLOGNAME    "ldapdiff"
21 #define SECTGLOB      "global"
22 #define DNNAME        "dn"
23 #define OCNAME        "objectClass"
24 
25 #define MAXCONFVAR     1024
26 #define MAXATTRLEN     4096
27 #define MAXLOGLEN      128
28 #define MAXLDIFLINELEN 64
29 
30 #define EXITLDOK       0
31 #define EXITLDERROR    1
32 #define EXITLDWARNING  2
33 
34 #define LDALLOC(x,y)  ldifalloc(x,y,__FILE__,__LINE__);
35 #define LDDUP(x)      ldifdup(x,__FILE__,__LINE__);
36 #define LDBINDUP(x,y) ldifbindup(x,y,__FILE__,__LINE__);
37 
38 typedef enum {
39         SECTIONGLOBAL,
40         SECTIONPROFILE,
41         SECTIONNONE
42 } tesectiontype;
43 
44 typedef enum {
45         CONFLDAPHOST,
46         CONFLDAPPORT,
47         CONFROOTDN,
48         CONFROOTPW,
49         CONFMODFILE,
50         CONFADDFILE,
51         CONFONLINEUPDATE,
52         CONFOFFLINEUPDATE,
53         CONFONLINEERRFATAL,
54         CONFICONV,
55         CONFLDIFCHARSET,
56         CONFLDAPCHARSET,
57         CONFSCHEMACHECK,
58         CONFSCHEMABASE,
59         CONFSCHEMAFILTER,
60         CONFSCHEMAATTRIBUTE,
61         CONFMANAGEDSAIT,
62         CONFBASEDN,
63         CONFFILTER,
64         CONFSCOPE,
65         CONFGROUP,
66         CONFIGNORE,
67         CONFIGNOREVAL,
68         CONFNOEQUALITY,
69         CONFMAPALIAS,
70         CONFDELETEENTRY,
71         CONFDELETEATTRIBUTE,
72         CONFMODIFYBYDELADD,
73 	CONFADDENTRY,
74         CONFNONE
75 } tevarid;
76 
77 typedef enum {
78         LOG0, /* print non fatal errors      */
79         LOG1, /* print statistics            */
80         LOG2  /* print debug informations    */
81 } teloglevel;
82 
83 typedef enum {
84         ATTRCHECK,
85         ATTRIGNORE
86 } teignore;
87 
88 typedef enum {
89         MODATTRADD,
90         MODATTRREPLACE,
91         MODATTRDELETE
92 } temodentry;
93 
94 typedef enum {
95 	MODADD,
96 	MODMODIFY,
97 	MODDELETE
98 } temod;
99 
100 typedef enum {
101         ATTRASC,
102         ATTRBIN,
103         ATTRUNKNOWN,
104         ATTREMPTY
105 } teattrtype;
106 
107 /* structure for config variables   */
108 struct s_conf {
109  char               *section;
110  tesectiontype       sectiontype;
111  tevarid             varid;
112  char               *var;
113  char               *val;
114 };
115 
116 /* pointered list of ldap values */
117 struct s_ldifval {
118  char             *val;        /* attribute value            */
119  size_t            val_len;    /* attribute value len        */
120  struct s_ldifval *next;
121 };
122 
123 /* pointered list of ldif attributes */
124 struct s_ldifentry {
125  char               *var;       /* attribute name             */
126  teattrtype          val_type;  /* attribute type             */
127  struct s_ldifval   *vallist;   /* attribute value(s)         */
128  struct s_ldifentry *next;      /* pointer to next attribute  */
129 };
130 
131 /* pointered list of ldif entries */
132 struct s_ldif {
133  char               *dnvar;     /* dn name (normally "dn")    */
134  char               *dnval;     /* dn value                   */
135  struct s_ldifentry *attrlist;  /* pointer to attributes list */
136  struct s_ldif      *next;      /* pointer to next entry      */
137 };
138 
139 /* pointered list of modify attribuites */
140 struct s_modentry {
141  char               *var;       /* attribute name             */
142  teattrtype          val_type;  /* attribute type             */
143  temodentry          modtype;
144  struct s_ldifval   *vallist;
145  struct s_modentry  *next;
146 };
147 
148 /* pointered list of modify entries */
149 struct s_mod {
150  char              *dnvar;
151  char              *dnval;
152  temod              modtype;
153  struct s_modentry *attrlist;
154  struct s_mod      *next;
155 };
156 
157 /* pointered list of schema attributes */
158 struct s_schema {
159  char                *var;
160  char               **at_names;
161  char                *at_sup_oid;
162  char                *at_equality_oid;
163  int                  at_single_value;
164  char                *real_equality_oid;
165  struct s_schema     *next;
166 };
167 
168 /* file ldaread.c   */
169 extern void           ldifread(struct s_ldif**,char*);
170 
171 /* file ldapiter.c  */
172 extern void           ldifiterldif(LDAP*,struct s_ldif*,struct s_mod**,struct s_schema*);
173 extern void           ldifiterldap(LDAP*,struct s_ldif*,struct s_mod**,struct s_schema*);
174 
175 /* file ldapcmp.c   */
176 extern void           ldifcmp(LDAP*,struct s_ldif*,struct s_ldif*,struct s_mod**,struct s_schema*);
177 extern void           ldifadddn(struct s_ldif*,struct s_mod**);
178 extern void           ldifdeletedn(char*,char*,struct s_mod**);
179 extern int            ldifdnalreadyexist(LDAP*,char*);
180 
181 /* file lapwrite.c  */
182 extern void           ldifwrite(struct s_mod*,struct s_schema*);
183 
184 /* file ldapmisc.c  */
185 extern char          *ldifnormalizedn(char*);
186 extern struct s_ldif* ldifadd(struct s_ldif**,char*,char*);
187 extern void           ldifaddentry(struct s_ldif*,char*,char*,size_t,teattrtype);
188 extern void           ldiffree(struct s_ldif**);
189 extern void          *ldifalloc(size_t,size_t,char*,int);
190 extern char          *ldifdup(char*,char*,int);
191 extern char          *ldifbindup(char*,size_t,char*,int);
192 extern int            ldifconfnormalize(char*,char*,char*);
193 extern void           ldiftrim(char*);
194 extern int            ldifgetfacility(char*);
195 extern teignore       ldifcheckignore(char*);
196 extern teignore       ldifcheckignoreval(char*);
197 extern int            ldifchecknoequality(char*);
198 extern char          *ldifcheckalias(char*);
199 extern int            ldifcheckbase(char*);
200 extern int            ldifgetscope();
201 
202 /* file ldaplog.c   */
203 extern void           ldiflogval(teloglevel,char*,char*,char*,size_t);
204 extern void           ldiflog(teloglevel,char*,...);
205 extern void           ldiflogbin(teloglevel,char*,...);
206 
207 /* file ldapconf.c  */
208 extern void           ldifinitconf(char*);
209 extern char          *ldifgetgconf(tevarid);
210 extern char          *ldifgetpconf(tevarid);
211 
212 /* file ldapmod.c   */
213 extern int            ldifmodify(LDAP*,struct s_mod*,struct s_schema*);
214 
215 /* file ldapstats.c */
216 extern void           ldifstats(struct s_mod*);
217 
218 /* file ldapiconv.c */
219 extern void           ldificonvopen();
220 extern int            ldificonv(char**,char**);
221 extern void           ldificonvclose();
222 
223 /* file ldapparse.c */
224 extern int            ldifparse(char*,char**,char**,size_t*,teattrtype*);
225 
226 /* file ldapschema.c */
227 extern void           ldifschemacreate(LDAP*,struct s_schema**);
228 extern void           ldifschemafree(struct s_schema**);
229 extern int            ldifschemaequal(struct s_schema*,char*);
230 extern char          *ldifschemarattr(struct s_schema*,char*);
231 extern void           ldifschemareplacealiases(struct s_ldif*,struct s_schema*);
232 
233 /* file ldapconnect.c */
234 extern void           ldifopen(LDAP**);
235 extern void           ldifclose(LDAP*);
236 
237 /* file ldapfilter.c */
238 extern void           ldif_bv2escaped_filter_value(char*,size_t,char**);
239 extern int            ldifgetfilter(struct s_ldifentry*,char**);
240 extern void           ldiffiltercheck(struct s_schema*);
241