#include #include #include #include "dnsconf.h" #include "internal.h" /* Replace or add a record in this DOMAIN definition. new_rec has been created with new. It will be managed (even deleted) by this function. */ PUBLIC int ZONE::set (FQHOST &fq, RECORD *new_rec) { /* #Specification: record file / multiple origin dnsconf can update with multiple $ORIGIN statement. It will find the closest origin. */ ORIGIN *match_ori = NULL; int nbori = origins.getnb(); int minlevel = 100; for (int i=0; iorigin.get(),hostpart); if (level > 0 && level < minlevel){ match_ori = ori; new_rec->sethostpart(hostpart); minlevel = level; } } if (match_ori != NULL){ match_ori->tbrec.add (new_rec); updatesoa(); } return 0; } /* Set one MX (or more) to a given priority */ PUBLIC void PRIMARY::setonemx ( FQHOST &fq, const char *mx, int priority, const char *ttl) { /* #Specification: domain / MX / priority Linuxconf does not let you enter the priority of the MX hosts. It computes a priority based on the order. Some need the ability to setup two or more MXs with the same priority. We use a trick. We specify the MX on the same line in the dialog and they will get the same priority. When editing back, they will be presented on the same line as well. */ SSTRINGS mxs; str_splitline (mx,' ',mxs); for (int m=0; mget(); RECORD_IN_MX *rec = new RECORD_IN_MX("dummy",priority,one); rec->setttl (ttl); set (fq,rec); } } /* Erase a record in this DOMAIN definition. new_rec has been created with new. It is used to find the record to delete. It is also deleted by this function. Return 1 if one record deleted, 0 otherwise */ PUBLIC int ZONE::unset (RECORD *new_rec) { bool found = false; for (int i=0; itbrec.getnb(); o++){ RECORD *rec = ori->tbrec.getitem(o); if (rec->cmp(new_rec) == 0){ ori->tbrec.remove_del(rec); o--; found = true; } } } if (found) updatesoa(); delete new_rec; return found ? 1 : 0; } /* Erase all records in this DOMAIN definition using the "left" element. */ PUBLIC int ZONE::unset_left (const char *left) { bool found = false; for (int i=0; itbrec.getnb(); o++){ RECORD *rec = ori->tbrec.getitem(o); if (rec->cmp_left(left) == 0){ ori->tbrec.remove_del(rec); o--; found = true; } } } if (found) updatesoa(); return 0; } /* Locate all record of a type using the left value as the key. */ PUBLIC int ZONE::locate_left ( FQHOST &fq, RECORD_TYPE rtype, RECORDS &recs) { recs.neverdelete(); for (int i=0; iorigin.get(),hostpart); if (level > 0){ for (int o=0; otbrec.getnb(); o++){ RECORD *rec = ori->tbrec.getitem(o); if (rec->is (rtype) && rec->cmp_left (hostpart)==0){ recs.add (rec); } } } } return recs.getnb(); } /* Locate all IP address from reverse mapping */ PUBLIC int ZONE::locate_rev ( const char *fullname, IP_ADDRS &tba) { for (int i=0; iorigin.get(); for (int o=0; otbrec.getnb(); o++){ RECORD *rec = ori->tbrec.getitem(o); if (rec->is (RTYPE_PTR) && rec->cmp_right (fullname)==0){ RECORD_IN_PTR *pt = (RECORD_IN_PTR*)rec; char revip[100]; sprintf (revip,"%s.%s",pt->addr.get(),dom); IP_ADDR *ra = new IP_ADDR(revip); ra->reverse(); tba.add(ra); } } } return tba.getnb(); } /* Locate all record of a type using the right value as the key. */ PUBLIC int ZONE::locate_right ( const char *value, RECORD_TYPE rtype, SSTRINGS &recs) { int ret = 0; for (int i=0; iorigin.get(); for (int o=0; otbrec.getnb(); o++){ RECORD *rec = ori->tbrec.getitem(o); if (rec->is (rtype) && rec->cmp_right (value)==0){ const char *name = rec->get_left(); if (name != NULL){ SSTRING *s = new SSTRING(name); int len = strlen(name); if (len > 0 && name[len-1] != '.'){ if (strcmp(name,"@")==0){ s->setfrom (suffix); }else{ s->append ("."); s->append (suffix); } } recs.add (s); ret++; } } } } return ret; } /* Locate all record of a type using the right value as the key. */ PUBLIC int PRIMARYS::locate_right ( const char *value, RECORD_TYPE rtype, SSTRINGS &recs) { int ret = 0; int n = getnb(); for (int i=0; ilocate_right(value,rtype,recs); } return ret; } /* Locate all host which point to a given IP. */ PUBLIC int DNS::locate_ip ( const char *ip, SSTRINGS &recs) { return primarys.locate_right (ip,RTYPE_A,recs); } /* Locate a domain in the DNS Return NULL if not found. */ PUBLIC PRIMARY *DNS::locate_domain(const char *domain) { PRIMARY *ret = NULL; for (int d=0; ddomain.icmp(domain)==0){ ret = p; break; } } return ret; } /* Enumerate all domains in the DNS */ PUBLIC void DNS::listdomains(SSTRINGS &tb) { for (int i=0; idomain)); } }