int main (int argc, char *argv[]) { int i = 0, j = 0; st_sql_t *sql = NULL; const char **row = NULL; if (!(sql = sql_open ("localhost", 3306, "root", "nb", "mysql", SQL_MYSQL))) return -1; sql_write (sql, "SELECT * FROM user"); for (i = 0; (row = (const char **) sql_getrow (sql, i)); i++) { for (j = 0; row[j]; j++) printf ("\"%s\" ", row[j]); printf ("\n"); } sql_write (sql, "SELECT * FROM user"); row = (const char **) sql_getrow (sql, 2); if (row) { for (j = 0; row[j]; j++) printf ("\"%s\" ", row[j]); printf ("\n"); } sql_write (sql, "SELECT * FROM user WHERE user = '******'"); for (i = 0; (row = (const char **) sql_getrow (sql, i)); i++) { for (j = 0; row[j]; j++) printf ("\"%s\" ", row[j]); printf ("\n"); } sql_close (sql); return 0; }
/************************************************************************************************** CHECK_XFER If the "xfer" column exists in the soa table, it should contain a list of wildcards separated by commas. In order for this zone transfer to continue, one of the wildcards must match the client's IP address. **************************************************************************************************/ static void check_xfer(TASK *t, MYDNS_SOA *soa) { SQL_RES *res = NULL; SQL_ROW row = NULL; char ip[256]; char *query = NULL; size_t querylen = 0; int ok = 0; memset(&ip, 0, sizeof(ip)); if (!mydns_soa_use_xfer) return; strncpy(ip, clientaddr(t), sizeof(ip)-1); querylen = sql_build_query(&query, "SELECT xfer FROM %s WHERE id=%u%s%s%s;", mydns_soa_table_name, soa->id, (mydns_rr_use_active)? " AND active='" : "", (mydns_rr_use_active)? mydns_rr_active_types[0] : "", (mydns_rr_use_active)? "'" : ""); res = sql_query(sql, query, querylen); RELEASE(query); if (!res) { ErrSQL(sql, "%s: %s", desctask(t), _("error loading zone transfer access rules")); } if ((row = sql_getrow(res, NULL))) { char *wild = NULL, *r = NULL; for (r = row[0]; !ok && (wild = strsep(&r, ",")); ) { if (strchr(wild, '/')) { if (t->family == AF_INET) ok = in_cidr(wild, t->addr4.sin_addr); } else if (wildcard_match(wild, ip)) ok = 1; } } sql_free(res); if (!ok) { dnserror(t, DNS_RCODE_REFUSED, ERR_NO_AXFR); axfr_reply(t); axfr_error(t, _("access denied")); } }
static taskexec_t ixfr_purge_all_soas(TASK *t, void *data) { /* * Retrieve all zone id's that have deleted records. * * For each zone get the expire field and delete any records that have expired. * */ SQL_RES *res = NULL; SQL_ROW row = NULL; size_t querylen; const char *QUERY0 = "SELECT DISTINCT zone FROM %s WHERE active='%s'"; const char *QUERY1 = "SELECT origin FROM %s " "WHERE id=%u;"; const char *QUERY2 = "DELETE FROM %s WHERE zone=%u AND active='%s' " " AND stamp < DATE_SUB(NOW(),INTERVAL %u SECOND);"; char *query = NULL; /* * Reset task timeout clock to some suitable value in the future */ t->timeout = current_time + ixfr_gc_interval; /* Try again e.g. tomorrow */ querylen = sql_build_query(&query, QUERY0, mydns_rr_table_name, mydns_rr_active_types[2]); if (!(res = sql_query(sql, query, querylen))) ErrSQL(sql, "%s: %s", desctask(t), _("error loading zone id's for DELETED records")); RELEASE(query); while((row = sql_getrow(res, NULL))) { unsigned int id = atou(row[0]); char *origin = NULL; MYDNS_SOA *soa = NULL; SQL_RES *sres = NULL; querylen = sql_build_query(&query, QUERY1, mydns_soa_table_name, id); if (!(res = sql_query(sql, query, querylen))) ErrSQL(sql, "%s: %s", desctask(t), _("error loading zone from DELETED record zone id")); RELEASE(query); if (!(row = sql_getrow(res, NULL))) { Warnx(_("%s: no soa found for soa id %u"), desctask(t), id); continue; } origin = row[0]; if (mydns_soa_load(sql, &soa, origin) == 0) { querylen = sql_build_query(&query, QUERY2, mydns_rr_table_name, soa->id, mydns_rr_active_types[2], soa->expire); if (sql_nrquery(sql, query, querylen) != 0) WarnSQL(sql, "%s: %s %s", desctask(t), _("error deleting expired records for zone "), soa->origin); RELEASE(query); sql_free(sres); } } sql_free(res); RELEASE(query); return (TASK_CONTINUE); }