summaryrefslogtreecommitdiffstats
path: root/policykit_roles/policykit_roles.xsl
blob: 09718ee9a13231608016b42906cbad1331cdef97 (plain)
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:md="http://freeipa.org/xsl/metadata/1.0"
  xmlns:xd="http://www.pnp-software.com/XSLTdoc"
  xmlns:pol="http://freeipa.org/xml/rng/policykit_roles/1.0">

  <md:output_handler>
    <file name="/tmp/policykit-SAFE.ldif" owner="root" group="root" permission="400"/>
  </md:output_handler>

  <xsl:param name="output_selector"/>

  <xsl:output method="text" indent="no"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <xsl:text># IPA generated ldif for policykit roles. DO NOT EDIT&#xA;&#xA;</xsl:text>
    <xsl:apply-templates select="pol:ipa"/>
  </xsl:template>

  <xsl:template match="pol:ipa">
    <xsl:apply-templates>
      <xsl:with-param name="pol:iparole"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="pol:metadata">
  </xsl:template>

  <xsl:template match="pol:iparole">
      <xsl:apply-templates select="pol:role"/>
  </xsl:template>

  <xsl:template match="pol:role">
    <xsl:text># role: </xsl:text>
    <xsl:value-of select="pol:name"/>
    <xsl:text>&#xA;</xsl:text>
    <xsl:text>dn: ou=</xsl:text>
    <xsl:value-of select="pol:name"/>
    <xsl:text>,ou=PolicyKitRoles,xx=some,xx=ldap,xx=path&#xA;&#xA;&#xA;</xsl:text>

    <xsl:apply-templates select="pol:action">
      <xsl:with-param name="rolename" select="pol:name"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="pol:action">
    <xsl:param name="rolename"/>

    <xsl:text>dn: ou=</xsl:text>
    <xsl:value-of select="pol:action_id"/>
    <xsl:text>,ou=</xsl:text>
    <xsl:value-of select="$rolename"/>
    <xsl:text>,ou=PolicyKitRoles,xx=some,xx=ldap,xx=path&#xA;</xsl:text>
    <xsl:text>changetype: modify&#xA;</xsl:text>
    <xsl:text>replace: allow_any&#xA;allow_any: </xsl:text>
    <xsl:value-of select="pol:allow_any"/>
    <xsl:text>&#xa;-&#xa;changetype: modify&#xA;</xsl:text>
    <xsl:text>replace: allow_inactive&#xA;allow_inactive: </xsl:text>
    <xsl:value-of select="pol:allow_inactive"/>
    <xsl:text>&#xa;-&#xa;changetype: modify&#xA;</xsl:text>
    <xsl:text>replace: allow_active&#xA;allow_active: </xsl:text>
    <xsl:value-of select="pol:allow_active"/>
    <xsl:text>&#xa;&#xA;</xsl:text>
  </xsl:template>


  <xsl:template match="pol:file">
    <xsl:choose>
      <xsl:when test="name(./*[1])='url'">
        <xsl:text>su - nobody 'curl -o /tmp/SAFE_TEMP_FILE </xsl:text>
        <xsl:value-of select="pol:url"/>
        <xsl:text>'&#xA;</xsl:text>
      </xsl:when>
      <xsl:when test="name(./*[1])='data'">
        <xsl:text>cat &#x3C;&#x3C; EOF | base64 -d > /tmp/SAFE_TEMP_FILE&#xA;</xsl:text>
        <xsl:value-of select="pol:data"/>
        <xsl:text>&#xA;EOF&#xA;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text># unknown element: </xsl:text>
        <xsl:value-of select="name(./*[1])"/>
        <xsl:text>&#xA;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:text>mv /tmp/SAFE_TEMP_FILE </xsl:text>
    <xsl:value-of select="pol:path"/>
    <xsl:text>&#xA;</xsl:text>

    <xsl:text>chown </xsl:text>
    <xsl:value-of select="pol:owner"/>
    <xsl:text>:</xsl:text>
    <xsl:value-of select="pol:group"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="pol:path"/>
    <xsl:text>&#xA;</xsl:text>
  </xsl:template>

  <xsl:template match="pol:run">
    <xsl:variable name="user">
      <xsl:choose>
        <xsl:when test="pol:user != ''">
          <xsl:value-of select="pol:user"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>nobody</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:text>su - </xsl:text>
    <xsl:value-of select="$user"/>
    <xsl:text> '</xsl:text>
    <xsl:value-of select="pol:command"/>
    <xsl:text>'&#xA;</xsl:text>
  </xsl:template>
   
</xsl:stylesheet>