This file is indexed.

/usr/share/sadms-2.0.15/sharesparser.py is in sadms 2.0.15.repack-0ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/python
# -*-coding: UTF-8 -*-
# bbou@ac-toulouse.fr
# GPL license
# 2005-08-09 19:07:31 
# sharesparser.py

import string
import re

#######################################################################
#	GLOBALS
#######################################################################

sysSetting={
	'testparm':'testparm -vs 2> /dev/null',

	'exists':'sh -c \'if [ -e "%FSOBJECT%" ]; then echo true; else echo false; fi\'',
	'getOwnerGroup':"stat -c '%U:%G' \"%FSOBJECT%\"",
	'getDirMode':"ls -dl \"%FSOBJECT%\" | cut -f 1 -d ' '",
}

#######################################################################
#	SHARE
#######################################################################

class Share:

	def printShare(self):
		print '\t#name=%s' % self.name
		print '\t#exists=%s' % self.pathExists
		if hasattr(self,'fsOwnerGroup'):
			print '\t#fsowner=%s.%s' % (self.fsOwnerGroup[0],self.fsOwnerGroup[1])
		if hasattr(self,'fsPerms'):
			print '\t#fsperms=%s' % self.fsPerms
		for p in self.props:
			print '\t%s = %s' % (p,self.props[p])
	pass

#######################################################################
#	SHARES
#######################################################################

class SharesParser:
	
	def __init__(self,runner):
		self.runner=runner;
		self.shares={}
		return

	# helpers

	def addShare(self,shares,sharename,share):
		if 'homes'==sharename:
			#share.props['path']='/home/%U'
			share.props['path']='<home>'
		# fsobject
		share.pathExists=False
		fsobject=share.props['path']
		if self.exists(fsobject):
			share.pathExists=True
			share.fsOwnerGroup=self.getOwnerGroup(fsobject)
			share.fsPerms=self.getMode(fsobject)
		shares[sharename]=share
		return

	def parse(self,output):
		shares={}
		lines=output.splitlines()
		sharename=None
		share=None
		for line in lines:
			# garbage line
			if re.match('^$',line):
				continue
			# section header line
			if re.match('^\[.*\]$',line):
				# terminate current share
				if share!=None:
					self.addShare(shares,sharename,share)
				share=None
				sharename=None
				# discard global and printers section
				if re.match('^\[global\]$',line) or re.match('^\[printers\]$',line):
					continue
				# start share
				sharename=line.lstrip('[').rstrip(']')											
				share=Share()
				share.name=sharename
				share.props=dict()
				continue
			# property line
			if sharename!=None:
				prop=line.split('=')
				name=prop[0].strip()
				value=prop[1].strip()
				share.props[name]=value
		# close open section			
		if share!=None:
			self.addShare(shares,sharename,share)

        	return shares

	def clip(self,lines,share):
		begin,end=(-1,-1)
		i=0
		for line in lines:
			if re.match('^\['+share+'\]$',line):
				begin=i
			elif begin!=-1 and end==-1 and re.match('^\[.*\]$',line):
				end=i
			i=i+1
					
		if begin!=-1 and end==-1:
			end=i

		# do not include comments or empty lines
		if begin!=-1 and end!=-1:
			for i in range(end-1,begin,-1):
				if re.match('^$',lines[i]) or re.match('^#',lines[i]) or re.match('^;',lines[i]):
					end=i
				else:
					break					
		return begin,end

	# debug

	def printShares(self,shares):
		for k in shares.keys():
			shares[k].printShare()

	def printConf(self,lines):
		for line in lines:
			print line,
		return

	#######################################################################
	#	HELPERS
	#######################################################################
	
	def runToString(self,cl):
		status,output=self.runner.runToString(cl)
		return status,output

	def getConf(self):
		cl=sysSetting['testparm']
		status,output=self.runToString(cl)
		if status:
			return output
		return ''

	def exists(self,path):
		cl=sysSetting['exists']
		cl=cl.replace('%FSOBJECT%',path)
		status,output=self.runToString(cl)
		if not status:
			return False
		output=output.strip('\n\r ')
		return output=='true'

	def getOwnerGroup(self,fsobject):
		cl=sysSetting['getOwnerGroup']
		cl=cl.replace('%FSOBJECT%',fsobject)
		status,output=self.runToString(cl)
		if not status:
			return None,None
		output=output.strip('\n\r ')
		return output.split(":")
	
	def getMode(self,fsobject):
		cl=sysSetting['getDirMode']
		cl=cl.replace('%FSOBJECT%',fsobject)
		status,output=self.runToString(cl)
		if not status:
			return None
		return output[1:10]

#######################################################################
#	MAIN
#######################################################################

import sys
import os
import runner

if __name__ == "__main__":
	e=sys.argv[0]
	e=os.path.realpath(e)
	d=os.path.dirname(e)
	os.chdir(d)
	p=SharesParser(runner.BasicRunner())
	conf=p.getConf()
	shares=p.parse(conf)
	for s in shares.keys():
		print '[%s]' % s
		shares[s].printShare()

__author__='Bernard Bou <bou@ac-toulouse.fr>'