diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-04-04 12:45:01 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-04-04 12:45:01 -0400 |
commit | 371561772c9073daf9033145b4b2156bc9f0e7dc (patch) | |
tree | 21dc090afcf3b87b7317ca43555ba0c0d0f687a4 | |
parent | 45794188f06ad3ab990f2c5d32cd2a67341475aa (diff) | |
download | vyos-cloud-init-371561772c9073daf9033145b4b2156bc9f0e7dc.tar.gz vyos-cloud-init-371561772c9073daf9033145b4b2156bc9f0e7dc.zip |
convert some user input from dos to unix (LP: #744965)
If user input is a consumed as a user-script, a boothook, or a upstart
job and appears to be dos-formated, then change it to unix formated
LP: #744965
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | cloudinit/__init__.py | 22 | ||||
-rw-r--r-- | cloudinit/util.py | 6 |
3 files changed, 14 insertions, 16 deletions
@@ -5,6 +5,8 @@ (LP: #739694) - fix bug in resizefs cloud-config that would cause trace based on failure of 'blkid /dev/root' (LP: #726938) + - convert dos formated files to unix for user-scripts, boothooks, + and upstart jobs (LP: #744965) 0.6.1: - fix bug in fixing permission on /var/log/cloud-init.log (LP: #704509) - improve comment strings in rsyslog file tools/21-cloudinit.conf diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 24e12d08..ab0a834a 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -393,14 +393,15 @@ class CloudInit: filename=filename.replace(os.sep,'_') scriptsdir = get_ipath_cur('scripts') util.write_file("%s/%s" % - (scriptsdir,filename), payload, 0700) + (scriptsdir,filename), util.dos2unix(payload), 0700) def handle_upstart_job(self,data,ctype,filename,payload): if ctype == "__end__" or ctype == "__begin__": return if not filename.endswith(".conf"): filename=filename+".conf" - util.write_file("%s/%s" % ("/etc/init",filename), payload, 0644) + util.write_file("%s/%s" % ("/etc/init",filename), + util.dos2unix(payload), 0644) def handle_cloud_config(self,data,ctype,filename,payload): if ctype == "__begin__": @@ -427,26 +428,15 @@ class CloudInit: if ctype == "__begin__": return filename=filename.replace(os.sep,'_') + payload = util.dos2unix(payload) prefix="#cloud-boothook" - dos=False start = 0 if payload.startswith(prefix): - start = len(prefix) - if payload[start] == '\r': - start=start+1 - dos = True - else: - if payload.find('\r\n',0,100) >= 0: - dos = True - - if dos: - payload=payload[start:].replace('\r\n','\n') - elif start != 0: - payload=payload[start:] + start = len(prefix) + 1 boothooks_dir = self.get_ipath("boothooks") filepath = "%s/%s" % (boothooks_dir,filename) - util.write_file(filepath, payload, 0700) + util.write_file(filepath, payload[start:], 0700) try: env=os.environ.copy() env['INSTANCE_ID']= self.datasource.get_instance_id() diff --git a/cloudinit/util.py b/cloudinit/util.py index fc4233de..8f6a6b0d 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -389,3 +389,9 @@ def shellify(cmdlist): else: content="%s%s\n" % ( content, str(args) ) return content + +def dos2unix(input): + # find first end of line + pos = input.find('\n') + if pos <= 0 or input[pos-1] != '\r': return(input) + return(input.replace('\r\n','\n')) |