From da506c19954a11534ebd6b6f1c0b760b0b438cd4 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Wed, 5 Sep 2007 17:15:13 +0200
Subject: [PATCH] Version 2007-09-05 17:15

M  src/hostinfo/named.py
M  src/hostinfo/samba.py
M  src/hostinfo/util.py
M  src/hostinfo/yp.py
---
 src/hostinfo/named.py |  4 ++--
 src/hostinfo/samba.py |  4 ++--
 src/hostinfo/util.py  |  2 +-
 src/hostinfo/yp.py    | 30 ++++++++++++++++++++++++++++++
 4 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/hostinfo/named.py b/src/hostinfo/named.py
index 2f1fc5b..17496f7 100755
--- a/src/hostinfo/named.py
+++ b/src/hostinfo/named.py
@@ -122,9 +122,9 @@ def forward(tree, domain):
         # Find all hosts that belong to this domain
         for (n, m) in net:
             if i.ip[0] and aton(i.ip[0]) & m == n:
-                host[i.name[0:]] = "A       %s" % i.ip[0]
+                host[i.name[1:]] = "A       %s" % i.ip[0]
                 for a in i._alias_:
-                    host[a.name[0]] = "CNAME   %s" % i.name[0:]
+                    host[a.name[0]] = "CNAME   %s" % i.name[1:]
 
     # Add a localhost entry
     result += "localhost       IN      A       127.0.0.1\n"
diff --git a/src/hostinfo/samba.py b/src/hostinfo/samba.py
index c6be5ac..8acfdc0 100755
--- a/src/hostinfo/samba.py
+++ b/src/hostinfo/samba.py
@@ -15,8 +15,8 @@ def share(tree, host):
                 "  browseable = no",
                 "  path = %s" % a.root[0],
                 "  writable = yes",
-                "  create mode = 0664",
-                "  directory mode = 0775"
+                "  create mode = 0644",
+                "  directory mode = 0755"
                 ])
             result += "\n\n"
     return result
diff --git a/src/hostinfo/util.py b/src/hostinfo/util.py
index 4c3d1de..1f51a3c 100755
--- a/src/hostinfo/util.py
+++ b/src/hostinfo/util.py
@@ -15,7 +15,7 @@ def fqn(tree, host):
     elif host.ip[0:]:
         for s in tree._subnet_:
             if aton(host.ip[0:]) & aton(s.netmask[0]) == aton(s.network[0]):
-                return "%s.%s." % (host.name[0:],s.domain[0])
+                return "%s.%s." % (host.name[1:],s.domain[0])
     else:
         raise Exception("'%s' not FQN, but has no ip" % host.name[0:])
 
diff --git a/src/hostinfo/yp.py b/src/hostinfo/yp.py
index 3761cf5..af1c68a 100755
--- a/src/hostinfo/yp.py
+++ b/src/hostinfo/yp.py
@@ -40,6 +40,34 @@ def ethers(tree):
             result += "%-15s %s\n" % (k, h)
     return result
 
+def adjust_netgroup(netgroup):
+    limit = 1000
+    result = {}
+    keys = netgroup.keys()
+    keys.sort()
+    for g in keys:
+        entries = netgroup[g]
+        entries.sort()
+        length = sum(map(len, entries)) + len(entries) * 5
+        if length < limit:
+            # group is less than max YP length (1024)
+            result[g] = entries
+        else:
+            # group is bigger than max YP length, split it
+            n = min(length / limit + 1, limit / (len(g) + 5))
+            m = len(entries) / n + 1
+            tmp = {}
+            tmp[g] = []
+            for i in range(n):
+                key = "%s__%d" % (g, i)
+                value = entries[i * m : (i + 1) * m]
+                if value:
+                    tmp[g].append(key)
+                    tmp[key] = value
+            for (k, v) in adjust_netgroup(tmp).iteritems():
+                result[k] = v
+    return result
+
 def netgroup(tree):
     netgroup = {}
     for m in tree._netgroup_._member_:
@@ -68,9 +96,11 @@ def netgroup(tree):
             except:
                 netgroup["ks-%s" % k.file[0:]] = [ entry ]
                 
+    netgroup = adjust_netgroup(netgroup)
     result = ""
     keys = netgroup.keys()
     keys.sort()
+
     for g in keys:
         result += "%s" % g
         entries = netgroup[g]
-- 
GitLab