10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * 3*3857Sstevel * Copyright 1998 Sun Microsystems, Inc. All rights reserved. 4*3857Sstevel * Use is subject to license terms. 50Sstevel@tonic-gate * 60Sstevel@tonic-gate */ 70Sstevel@tonic-gate 80Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 90Sstevel@tonic-gate 100Sstevel@tonic-gate /* 110Sstevel@tonic-gate * structs for storing and updating entries 120Sstevel@tonic-gate */ 130Sstevel@tonic-gate 140Sstevel@tonic-gate #if !defined(_ENTRY_H_) && !defined(_PROTO_SLAP) 150Sstevel@tonic-gate #define _ENTRY_H_ 160Sstevel@tonic-gate 170Sstevel@tonic-gate #ifndef _SLDAPD_H_ 180Sstevel@tonic-gate 190Sstevel@tonic-gate /* 200Sstevel@tonic-gate * represents an attribute (type + values + syntax + oid) 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate typedef struct attr { 230Sstevel@tonic-gate char *a_type; 240Sstevel@tonic-gate struct berval **a_vals; 250Sstevel@tonic-gate int a_syntax; 260Sstevel@tonic-gate struct attr *a_next; 270Sstevel@tonic-gate } Attribute; 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * the attr_syntax() routine returns one of these values 310Sstevel@tonic-gate * telling what kind of syntax an attribute supports. 320Sstevel@tonic-gate * 330Sstevel@tonic-gate * NOTE: The syntax may not be available in libentry unless you have 340Sstevel@tonic-gate * read the slapd.conf config file. 350Sstevel@tonic-gate */ 360Sstevel@tonic-gate #define SYNTAX_CIS 0x01 /* case insensitive string */ 370Sstevel@tonic-gate #define SYNTAX_CES 0x02 /* case sensitive string */ 380Sstevel@tonic-gate #define SYNTAX_BIN 0x04 /* binary data */ 390Sstevel@tonic-gate #define SYNTAX_TEL 0x08 /* telephone number string */ 400Sstevel@tonic-gate #define SYNTAX_DN 0x10 /* dn string */ 410Sstevel@tonic-gate #define SYNTAX_LONG 0x20 /* integer */ 420Sstevel@tonic-gate #define SYNTAX_ULONG 0x40 /* integer */ 430Sstevel@tonic-gate #define SYNTAX_CRYPT 0x80 /* crypted password */ 440Sstevel@tonic-gate #define SYNTAX_UTCTIME 0x0100 /* Utctime string YYMMDDhhmm[ss]Z */ 450Sstevel@tonic-gate #define SYNTAX_GENTIME 0x0200 /* gentime string YYYYMMDDhhmm[ss]Z */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* These next two are used by libentry. They are overloaded into a_syntax 480Sstevel@tonic-gate * because there's no extra room and we didn't want to enlarge the structure 490Sstevel@tonic-gate * because of the performance hit. 500Sstevel@tonic-gate */ 510Sstevel@tonic-gate #define ATTRIBUTE_FOUND 0x1000 /* Set if attribute was found */ 520Sstevel@tonic-gate #define ATTRIBUTE_ADD 0x2000 /* Set if values are to be added instead of replaced */ 530Sstevel@tonic-gate 540Sstevel@tonic-gate #define DEFAULT_SYNTAX SYNTAX_CIS 550Sstevel@tonic-gate 560Sstevel@tonic-gate typedef struct asyntaxinfo { 570Sstevel@tonic-gate char **asi_names; 580Sstevel@tonic-gate char *asi_oid; 590Sstevel@tonic-gate int asi_options; 600Sstevel@tonic-gate #define ATTR_OPT_SINGLE 0x01 /* Single Valued attr */ 610Sstevel@tonic-gate #define ATTR_OPT_OPERATIONAL 0x02 /* Operational attr */ 620Sstevel@tonic-gate #define ATTR_OPT_NAMING 0x10 /* Naming Attribute */ 630Sstevel@tonic-gate char *asi_default_oc; 640Sstevel@tonic-gate int asi_maxlen; 650Sstevel@tonic-gate int asi_syntax; 660Sstevel@tonic-gate } AttrSyntaxInfo; 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * the id used in the indexes to refer to an entry 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate typedef unsigned int ID; 720Sstevel@tonic-gate #define NOID ((unsigned int)-1) 730Sstevel@tonic-gate 740Sstevel@tonic-gate /* 750Sstevel@tonic-gate * represents an entry in core 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate typedef struct entry { 780Sstevel@tonic-gate char *e_dn; /* DN of this entry */ 790Sstevel@tonic-gate Attribute *e_attrs; /* list of attributes + values */ 800Sstevel@tonic-gate 810Sstevel@tonic-gate ID e_id; /* not used in libentry */ 820Sstevel@tonic-gate char e_state; /* only ENTRY_FOUND is used below */ 830Sstevel@tonic-gate #define ENTRY_STATE_DELETED 0x01 /* value not used in libentry */ 840Sstevel@tonic-gate #define ENTRY_STATE_CREATING 0x02 /* value not used in libentry */ 850Sstevel@tonic-gate int e_refcnt; /* # threads ref'ing this entry */ 860Sstevel@tonic-gate pthread_mutex_t e_mutex; /* to lock for add/modify */ 870Sstevel@tonic-gate struct entry *e_lrunext; 880Sstevel@tonic-gate struct entry *e_lruprev; /* not used in libentry, (could be added) */ 890Sstevel@tonic-gate } Entry; 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* This next #define is used by libentry. It is overloaded into e_state. 920Sstevel@tonic-gate * It is used to mark entries as found/not found so that they can be deleted 930Sstevel@tonic-gate * if they are not found (for example on a remote replica). 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate #define ENTRY_FOUND 0x80 960Sstevel@tonic-gate 970Sstevel@tonic-gate #endif _SLDAPD_H_ 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* entry.c */ 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* output_ldif takes a modlist structure and prints out ldif. Since there are 3 ways 1020Sstevel@tonic-gate * you can use a modlist structure, you need to tell this routine what you're doing. 1030Sstevel@tonic-gate * The three choices are: 1040Sstevel@tonic-gate * LDAP_MODIFY_ENTRY 1050Sstevel@tonic-gate * LDAP_ADD_ENTRY 1060Sstevel@tonic-gate * LDAP_DELETE_ENTRY 1070Sstevel@tonic-gate * ldif suitable for feeding to ldapmodify will be produced. 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate /* op arg to output_ldif() */ 1110Sstevel@tonic-gate #define LDAP_MODIFY_ENTRY 1 1120Sstevel@tonic-gate #define LDAP_ADD_ENTRY 2 1130Sstevel@tonic-gate #define LDAP_DELETE_ENTRY 3 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate void output_ldif(char *dn, int op, LDAPMod **modlist, FILE *out); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* Checks that base exist. If not, create it. 1180Sstevel@tonic-gate * ld - ldap context, you must supply it because it's used in ldap_search 1190Sstevel@tonic-gate * out - file to output ldif to. If supplied, ldif will be printed here, 1200Sstevel@tonic-gate * if not supplied, ldap_mod will be called for you (using ld). 1210Sstevel@tonic-gate * 1220Sstevel@tonic-gate * returns number of entries created if all is ok, -1 if an error occured. 1230Sstevel@tonic-gate * 1240Sstevel@tonic-gate * mutex locks: if you are outputting to out from other threads, you need 1250Sstevel@tonic-gate * to lock output_mutex. output_ldif locks this mutex before outputting. 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate int make_base(LDAP *ld, FILE *out, char *base); 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate /* Add an entry to ldap. You supply an Entry struct. Will either add entry 1310Sstevel@tonic-gate * to ldap or output ldif to an open file (stdout for example). 1320Sstevel@tonic-gate * 1330Sstevel@tonic-gate * ld - ldap context. Must be valid if you want entry_add to add entries to ldap 1340Sstevel@tonic-gate * for you. 1350Sstevel@tonic-gate * out - open file where to send ldif output. One of ld or out should be valid. 1360Sstevel@tonic-gate * new_entry is an Entry which you want added to ldap 1370Sstevel@tonic-gate * 1380Sstevel@tonic-gate * returns number of entries created or -1 if an error occured in ldap_add() 1390Sstevel@tonic-gate */ 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate int entry_add(LDAP *ld, FILE *out, Entry *new_entry); 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate /* Compares two entries and issue changes to make old look like new. 1440Sstevel@tonic-gate * 1450Sstevel@tonic-gate * ld - ldap context. Must be valid if you want entry_update to add entries to ldap 1460Sstevel@tonic-gate * for you. 1470Sstevel@tonic-gate * out - open file where to send ldif output. One of ld or out should be valid. 1480Sstevel@tonic-gate * new_entry is an Entry which you want old_entry to look like 1490Sstevel@tonic-gate * 1500Sstevel@tonic-gate * returns number of entries modified or -1 if an error occured in ldap_modify() 1510Sstevel@tonic-gate */ 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate int entry_update(LDAP *ld, FILE *out, Entry *old_entry, Entry *new_entry); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* Deletes an entry. 1560Sstevel@tonic-gate * ld - ldap context. Must be valid if you want delete_entry to call ldap 1570Sstevel@tonic-gate * for you. 1580Sstevel@tonic-gate * out - open file where to send ldif output. One of ld or out should be valid. 1590Sstevel@tonic-gate * ldap_entry is an Entry which you want to delete 1600Sstevel@tonic-gate * 1610Sstevel@tonic-gate * returns number of entries deleted or -1 if an error occured in ldap_modify() 1620Sstevel@tonic-gate * usually one, but for future it might delete more than one. 1630Sstevel@tonic-gate */ 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate int entry_delete(LDAP *ld, FILE *out, Entry *ldap_entry); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* attr.c */ 1680Sstevel@tonic-gate void attr_free( Attribute *a ); 1690Sstevel@tonic-gate int attr_merge_fast( 1700Sstevel@tonic-gate Entry *e, 1710Sstevel@tonic-gate char *type, 1720Sstevel@tonic-gate struct berval **vals, 1730Sstevel@tonic-gate int nvals, 1740Sstevel@tonic-gate int naddvals, 1750Sstevel@tonic-gate int *maxvals, 1760Sstevel@tonic-gate Attribute ***a 1770Sstevel@tonic-gate ); 1780Sstevel@tonic-gate int attr_merge( 1790Sstevel@tonic-gate Entry *e, 1800Sstevel@tonic-gate char *type, 1810Sstevel@tonic-gate struct berval **vals 1820Sstevel@tonic-gate ); 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate Attribute *attr_find( 1850Sstevel@tonic-gate Attribute *a, 1860Sstevel@tonic-gate char *type, 1870Sstevel@tonic-gate int ignoreOpt 1880Sstevel@tonic-gate ); 1890Sstevel@tonic-gate int attr_delete( 1900Sstevel@tonic-gate Attribute **attrs, 1910Sstevel@tonic-gate char *type 1920Sstevel@tonic-gate ); 1930Sstevel@tonic-gate int attr_syntax( char *type ); 1940Sstevel@tonic-gate int attr_syntax_by_oid( char *oid ); 1950Sstevel@tonic-gate void attr_syntax_config( 1960Sstevel@tonic-gate char *fname, 1970Sstevel@tonic-gate int lineno, 1980Sstevel@tonic-gate int argc, 1990Sstevel@tonic-gate char **argv 2000Sstevel@tonic-gate ); 2010Sstevel@tonic-gate char * attr_normalize( char *s ); 2020Sstevel@tonic-gate char * alias_normalize( char *s ); 2030Sstevel@tonic-gate int type_compare(char * t1, char *t2); 2040Sstevel@tonic-gate int type_list_compare( 2050Sstevel@tonic-gate char **a, 2060Sstevel@tonic-gate char *s 2070Sstevel@tonic-gate ); 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate int attr_cmp(Attribute *attr1, Attribute *attr2); 2100Sstevel@tonic-gate char * get_type_from_list(char **a, char *s); 2110Sstevel@tonic-gate int attr_single_valued_check(char *type, struct berval **vals); 2120Sstevel@tonic-gate AttrSyntaxInfo *get_attrSyntaxInfo(char *type); 2130Sstevel@tonic-gate char * attr_syntax2oid(int aSyntax); 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate /* value.c */ 2160Sstevel@tonic-gate int value_add_fast( 2170Sstevel@tonic-gate struct berval ***vals, 2180Sstevel@tonic-gate struct berval **addvals, 2190Sstevel@tonic-gate int nvals, 2200Sstevel@tonic-gate int naddvals, 2210Sstevel@tonic-gate int *maxvals 2220Sstevel@tonic-gate ); 2230Sstevel@tonic-gate int value_delete( 2240Sstevel@tonic-gate struct berval ***vals, 2250Sstevel@tonic-gate struct berval *v, 2260Sstevel@tonic-gate int syntax, 2270Sstevel@tonic-gate int normalize 2280Sstevel@tonic-gate ); 2290Sstevel@tonic-gate int value_add_one( 2300Sstevel@tonic-gate struct berval ***vals, 2310Sstevel@tonic-gate struct berval *v, 2320Sstevel@tonic-gate int syntax, 2330Sstevel@tonic-gate int normalize 2340Sstevel@tonic-gate ); 2350Sstevel@tonic-gate time_t utc2seconds(char * utctime); 2360Sstevel@tonic-gate int value_add( 2370Sstevel@tonic-gate struct berval ***vals, 2380Sstevel@tonic-gate struct berval **addvals 2390Sstevel@tonic-gate ); 2400Sstevel@tonic-gate void value_normalize( 2410Sstevel@tonic-gate char *s, 2420Sstevel@tonic-gate int syntax 2430Sstevel@tonic-gate ); 2440Sstevel@tonic-gate int value_cmp( 2450Sstevel@tonic-gate struct berval *v1, 2460Sstevel@tonic-gate struct berval *v2, 2470Sstevel@tonic-gate int syntax, 2480Sstevel@tonic-gate int normalize /* 1 => arg 1; 2 => arg 2; 3 => both */ 2490Sstevel@tonic-gate ); 2500Sstevel@tonic-gate int value_ncmp( 2510Sstevel@tonic-gate struct berval *v1, 2520Sstevel@tonic-gate struct berval *v2, 2530Sstevel@tonic-gate int syntax, 2540Sstevel@tonic-gate int len, 2550Sstevel@tonic-gate int normalize 2560Sstevel@tonic-gate ); 2570Sstevel@tonic-gate int value_find( 2580Sstevel@tonic-gate struct berval **vals, 2590Sstevel@tonic-gate struct berval *v, 2600Sstevel@tonic-gate int syntax, 2610Sstevel@tonic-gate int normalize 2620Sstevel@tonic-gate ); 2630Sstevel@tonic-gate int value_cnt(struct berval **vals); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate /* dn.c */ 2660Sstevel@tonic-gate char *dn_normalize( char *dn ); 2670Sstevel@tonic-gate char *dn_normalize_case( char *dn ); 2680Sstevel@tonic-gate int dn_issuffix(char *dn, char *suffix); 2690Sstevel@tonic-gate char *dn_upcase( char *dn ); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate #endif _ENTRY_H_ 272