Allowed = None;
CurrentHost = "";
+def Sanitize(Str):
+ return string.translate(Str,string.maketrans("\n\r\t","$$$"));
+
# See if this user is in the group list
def IsInGroup(DnRecord):
global Allowed,CurrentHost;
for x in PasswdAttrs:
if x[1].has_key("uidnumber") == 0 or IsInGroup(x) == 0:
continue;
-
+
+ # Do not let people try to buffer overflow some busted passwd parser.
+ if len(GetAttr(x,"gecos")) > 100 or len(GetAttr(x,"loginshell")) > 50:
+ continue;
+
Line = "%s:x:%s:%s:%s:%s%s:%s\n" % (GetAttr(x,"uid"),\
GetAttr(x,"uidnumber"),GetAttr(x,"gidnumber"),\
GetAttr(x,"gecos"),HomePrefix,GetAttr(x,"uid"),\
continue;
Pass = GetAttr(x,"userpassword");
- if Pass[0:7] != "{crypt}":
+ if Pass[0:7] != "{crypt}" or len(Pass) > 50:
Pass = '*';
else:
Pass = Pass[7:];
- Line = "%s:%s:%s:%s:%s:%s:%s:%s:\n" % (GetAttr(x,"uid"),\
+ Line = "%s:%s:%s:%s:%s:%s:%s:%s:" % (GetAttr(x,"uid"),\
Pass,GetAttr(x,"shadowlastchange"),\
GetAttr(x,"shadowmin"),GetAttr(x,"shadowmax"),\
GetAttr(x,"shadowwarning"),GetAttr(x,"shadowinactive"),\
GetAttr(x,"shadowexpire"));
+ Line = Sanitize(Line) + "\n";
F.write(Line);
Fdb.write("0%u %s" % (I,Line));
Fdb.write(".%s %s" % (GetAttr(x,"uid"),Line));
raise;
Done(File,F,Fdb);
+# Generate the shadow list
+def GenSSHShadow(l,File):
+ F = None;
+ Fdb = None;
+ try:
+ OldMask = os.umask(0077);
+ F = open(File + ".tmp","w",0600);
+ Fdb = None;
+ os.umask(OldMask);
+
+ # Fetch all the users
+ global PasswdAttrs;
+ if PasswdAttrs == None:
+ raise "No Users";
+
+ I = 0;
+ for x in PasswdAttrs:
+ if x[1].has_key("uidnumber") == 0 or IsInGroup(x) == 0 or \
+ x[1].has_key("sshrsaauthkey") == 0:
+ continue;
+ for I in x[1]["sshrsaauthkey"]:
+ Line = "%s: %s" %(GetAttr(x,"uid"),I);
+ Line = Sanitize(Line) + "\n";
+ F.write(Line);
+
+ # Oops, something unspeakable happened.
+ except:
+ Die(F,Fdb);
+ raise;
+ Done(File,F,Fdb);
+
# Generate the group list
def GenGroup(l,File):
F = None;
for I in GroupMap[x]:
Line = Line + ("%s%s" % (Comma,I));
Comma = ',';
- Line = Line + '\n';
+ Line = Sanitize(Line) + "\n";
F.write(Line);
Fdb.write("0%u %s" % (Counter,Line));
Fdb.write(".%s %s" % (x,Line));
for x in PasswdAttrs:
if x[1].has_key("emailforward") == 0 or IsInGroup(x) == 0:
continue;
- Line = "%s: %s\n" % (GetAttr(x,"uid"),GetAttr(x,"emailforward"));
+
+ # Do not allow people to try to buffer overflow busted parsers
+ if len(GetAttr(x,"emailforward")) > 200:
+ continue;
+
+ Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailforward"));
+ Line = Sanitize(Line) + "\n";
F.write(Line);
# Oops, something unspeakable happened.
if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
continue;
try:
- F.write("%8s %8s \"\"\n"%(DecDegree(x,"latitude",1),DecDegree(x,"longitude",1)));
+ Line = "%8s %8s \"\""%(DecDegree(x,"latitude",1),DecDegree(x,"longitude",1));
+ Line = Sanitize(Line) + "\n";
+ F.write(Line);
except:
pass;
"gecos","loginshell","userpassword","shadowlastchange",\
"shadowmin","shadowmax","shadowwarning","shadowinactive",
"shadowexpire","emailforward","latitude","longitude",\
- "allowedhosts"]);
+ "allowedhosts","sshrsaauthkey"]);
# Open the control file
if len(sys.argv) == 1:
GenPasswd(l,OutDir+"passwd",Split[1]);
GenGroup(l,OutDir+"group");
GenShadow(l,OutDir+"shadow");
+ GenSSHShadow(l,OutDir+"ssh-rsa-shadow");
GenForward(l,OutDir+"forward-alias");
GenMarkers(l,OutDir+"markers");