1 # =====================================================================
2 # groupAuthList.awk: RPC I/O function for rpclib/groupAuthList.
3 #
4 # Copyright (c) 2007,2008,2009,2010 Carlo Strozzi
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 dated June, 1991.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # =====================================================================
20
21 # =====================================================================
22 # void _userproc(int mode)
23 # =====================================================================
24
25 function _userproc(mode, value,outfile,i,j,a,fmt) {
26
27 if (mode == _O_REQUEST) { # request.
28
29 # target group
30 value = _request("1",1)
31
32 # group must not be null and it may not contain the
33 # unescaped ``.'' character.
34
35 if (value != _NULL && value !~ /\./) {
36 _rcset("cgi.group",unixify(value))
37 _rcset("cgi.group.literal",value)
38 }
39
40 # what to list:
41 #
42 # groups: available authorization groups
43 # users: available authorization users
44
45 value = _request("2",1)
46
47 # add more types as needed.
48 if (value ~ /^(users|groups)$/) _rcset("cgi.what",value)
49
50 # The following test is necessary since the address could,
51 # at least in theory, have been set to any string by the
52 # remote user, due to how it is handled to cope with stunnel(8)
53 # and the lack of transproxy support in kernel 2.4.x.
54
55 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE)
56 value = ENVIRON["REMOTE_ADDR"]
57 else value = "0.0.0.0"
58
59 _rcset("REMOTE_ADDR",value)
60 }
61
62 else { # response
63
64 outfile = _rcget("tpl.include.tw.page")
65 if (outfile !~ /^\/\.*[a-zA-Z0-9]/)
66 return(_sys("csaExit.fault 0041 outfile"))
67
68 # Set output format string.
69
70 fmt = readfmt("tw-group-authlist")
71 gsub(/%/,"%%",fmt) # turn plain '%' into '%%'.
72 gsub(/\\/,"\\\\&",fmt) # turn '\' into '\\'.
73 gsub(/[\n\r]+/,"",fmt) # just in case.
74
75 # this format string is currently not customizable.
76 if (!sub(//,"%s",fmt)) fmt = fmt ""
77
78 # encode any extra markers.
79 gsub(//, "\\<tw:s/\\>",fmt)
80
81 fmt = fmt "\n"
82
83 # read input table.
84
85 value=_NULL; i=1
86 while (split(_TBLS[1,i++],a,"\t")) value = value "," a[1]
87
88 gsub(/,+/,",",value); sub(/^,+/,"",value); sub(/,+$/,"",value)
89
90 i=split(value,a,","); _sort(a,i); i=_uniq(a,i)
91
92 while (++j <= i) {
93
94 printf(fmt,_xmlencode(a[j])) > outfile
95
96 # Provide also a machine-readable format.
97 _wsresponse(1,j,a[j])
98 }
99
100 close(outfile)
101
102 # generic template conditionals.
103
104 ifsections()
105 }
106 }
107
108 # EOF