[PATCH 3/4] s4: dns update, allow to have a static list of grants
Matthieu Patou
mat at matws.net
Sun Mar 28 11:25:26 MDT 2010
---
source4/dsdb/dns/dns_update.c | 61 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/source4/dsdb/dns/dns_update.c b/source4/dsdb/dns/dns_update.c
index 4e6ee83..142354a 100644
--- a/source4/dsdb/dns/dns_update.c
+++ b/source4/dsdb/dns/dns_update.c
@@ -87,6 +87,48 @@ static void dnsupdate_rndc_done(struct tevent_req *subreq)
}
}
+static char* get_static_entries(TALLOC_CTX *ctx ,const char *path)
+{
+ int fd;
+ char* buffer;
+ ssize_t read_bytes;
+ const size_t increment = 8192;
+ size_t offset = 0;
+ size_t size = increment + 1;
+
+ fd = open(path, O_RDONLY);
+ if ( fd == -1 )
+ return NULL;
+ buffer = (char*) talloc_array(ctx, char*, size);
+ if( buffer == NULL ) {
+ DEBUG(0,(__location__ ": Unable to allocate buffer for reading static dns policy entries"));
+ close(fd);
+ return NULL;
+ }
+
+ read_bytes = read(fd, buffer, increment);
+ while( read_bytes == increment)
+ {
+ size += increment;
+ offset += increment;
+ buffer = (char*) talloc_realloc(ctx, buffer, char *, size);
+ if( buffer == NULL ) {
+ DEBUG(0,(__location__ ": Unable to reallocate buffer for reading static dns policy entries"));
+ close(fd);
+ return NULL;
+ }
+ read_bytes = read(fd, buffer + offset, increment);
+ }
+ if( read_bytes < 0 ) {
+ DEBUG(0,(__location__ ": Error while reading %s: %s", path, strerror(errno)));
+ close(fd);
+ return NULL;
+ }
+ close(fd);
+ buffer[offset+read_bytes-1] = '\0';
+ return buffer;
+}
+
/*
called every 'dnsupdate:conf interval' seconds
*/
@@ -94,7 +136,8 @@ static void dnsupdate_rebuild(struct dnsupdate_service *service)
{
int ret;
struct ldb_result *res;
- const char *tmp_path, *path;
+ const char *tmp_path, *path, *path_static;
+ char *static_policies;
int fd;
unsigned int i;
const char *attrs[] = { "sAMAccountName", NULL };
@@ -119,13 +162,20 @@ static void dnsupdate_rebuild(struct dnsupdate_service *service)
path = private_path(tmp_ctx, service->task->lp_ctx, "named.conf.update");
}
+ path_static = lp_parm_string(service->task->lp_ctx, NULL, "dnsupdate", "extra_static_grant_rules");
+ if (path_static == NULL) {
+ path_static = private_path(tmp_ctx, service->task->lp_ctx, "named.conf.update.static");
+ }
+
tmp_path = talloc_asprintf(tmp_ctx, "%s.tmp", path);
- if (path == NULL || tmp_path == NULL) {
- DEBUG(0,(__location__ ": Unable to get paths"));
+ if (path == NULL || tmp_path == NULL || path_static == NULL ) {
+ DEBUG(0,(__location__ ": Unable to get paths\n"));
talloc_free(tmp_ctx);
return;
}
+ static_policies = get_static_entries(tmp_ctx, path_static);
+
unlink(tmp_path);
fd = open(tmp_path, O_CREAT|O_TRUNC|O_WRONLY, 0444);
if (fd == -1) {
@@ -136,6 +186,11 @@ static void dnsupdate_rebuild(struct dnsupdate_service *service)
dprintf(fd, "/* this file is auto-generated - do not edit */\n");
dprintf(fd, "update-policy {\n");
+ if( static_policies != NULL ) {
+ dprintf(fd, "/* Start of static entries */\n");
+ dprintf(fd, "%s\n",static_policies);
+ dprintf(fd, "/* End of static entries */\n");
+ }
dprintf(fd, "\tgrant %s ms-self * A AAAA;\n", realm);
dprintf(fd, "\tgrant administrator@%s wildcard * A AAAA SRV CNAME TXT;\n", realm);
--
1.6.3.3
--------------080803050903060508040901
Content-Type: text/x-patch;
name="0004-s4-pass-config-file-location-to-samba_dnsupdate.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename*0="0004-s4-pass-config-file-location-to-samba_dnsupdate.patch"
More information about the samba-technical
mailing list