Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-cloud / recipes-support / ldapscripts / files / sudo-support.patch
1 Index: ldapscripts-2.0.8/sbin/ldapaddsudo
2 ===================================================================
3 --- /dev/null
4 +++ ldapscripts-2.0.8/sbin/ldapaddsudo
5 @@ -0,0 +1,63 @@
6 +#!/bin/sh
7 +
8 +#  ldapaddsudo : adds a sudoRole to LDAP
9 +
10 +#  Copyright (C) 2005 Ganaël LAPLANCHE - Linagora
11 +#  Copyright (C) 2006-2013 Ganaël LAPLANCHE
12 +#  Copyright (c) 2014 Wind River Systems, Inc.
13 +#
14 +#  This program is free software; you can redistribute it and/or
15 +#  modify it under the terms of the GNU General Public License
16 +#  as published by the Free Software Foundation; either version 2
17 +#  of the License, or (at your option) any later version.
18 +#
19 +#  This program is distributed in the hope that it will be useful,
20 +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
21 +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 +#  GNU General Public License for more details.
23 +#
24 +#  You should have received a copy of the GNU General Public License
25 +#  along with this program; if not, write to the Free Software
26 +#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 +#  USA.
28 +
29 +if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]
30 +then
31 +  echo "Usage : $0 <username>"
32 +  exit 1
33 +fi
34 +
35 +# Source runtime file
36 +_RUNTIMEFILE="/usr/lib/ldapscripts/runtime"
37 +. "$_RUNTIMEFILE"
38 +
39 +# Username = first argument
40 +_USER="$1"
41 +
42 +# Use template if necessary
43 +if [ -n "$STEMPLATE" ] && [ -r "$STEMPLATE" ]
44 +then
45 +  _getldif="cat $STEMPLATE"
46 +else
47 +  _getldif="_extractldif 2"
48 +fi
49 +
50 +# Add sudo entry to LDAP
51 +$_getldif | _filterldif | _askattrs | _utf8encode | _ldapadd
52 +
53 +[ $? -eq 0 ] || end_die "Error adding user $_USER to LDAP"
54 +echo_log "Successfully added sudo access for user $_USER to LDAP"
55 +
56 +end_ok
57 +
58 +# Ldif template ##################################
59 +##dn: cn=<user>,ou=SUDOers,<usuffix>,<suffix>
60 +##objectClass: top
61 +##objectClass: sudoRole
62 +##cn: <user>
63 +##sudoUser: <user>
64 +##sudoHost: ALL
65 +##sudoRunAsUser: ALL
66 +##sudoCommand: ALL
67 +###sudoOrder: <default: 0, if multiple entries match, this entry with the highest sudoOrder is used>
68 +###sudoOption: <specify other sudo specific attributes here>
69 Index: ldapscripts-2.0.8/sbin/ldapmodifyuser
70 ===================================================================
71 --- ldapscripts-2.0.8.orig/sbin/ldapmodifyuser
72 +++ ldapscripts-2.0.8/sbin/ldapmodifyuser
73 @@ -19,9 +19,11 @@
74  #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
75  #  USA.
76  
77 -if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]
78 +if [ "$1" = "-h" ] || [ "$1" = "--help" ] || \
79 +   [[ "$2" != "add" && "$2" != "replace" && "$2" != "delete" ]] || \
80 +   [ "$#" -ne 4 ]
81  then
82 -  echo "Usage : $0 <username | uid>"
83 +  echo "Usage : $0 <username | uid> [<add | replace | delete> <field> <value>]"
84    exit 1
85  fi
86  
87 @@ -33,21 +35,48 @@ _RUNTIMEFILE="/usr/lib/ldapscripts/runti
88  _findentry "$USUFFIX,$SUFFIX" "(&(objectClass=posixAccount)(|(uid=$1)(uidNumber=$1)))"
89  [ -z "$_ENTRY" ] && end_die "User $1 not found in LDAP"
90  
91 -# Allocate and create temp file
92 -mktempf
93 -echo "dn: $_ENTRY" > "$_TMPFILE" || end_die "Error writing to temporary file $_TMPFILE"
94 -
95 -# Display entry
96 -echo "# About to modify the following entry :"
97 -_ldapsearch "$_ENTRY"
98 -
99 -# Edit entry
100 -echo "# Enter your modifications here, end with CTRL-D."
101 -echo "dn: $_ENTRY"
102 -cat >> "$_TMPFILE" || end_die "Error writing to temporary file $_TMPFILE"
103 +# Username = first argument
104 +_USER="$1"
105 +
106 +if [ "$#" -eq 1 ]
107 +then
108 +  # Allocate and create temp file
109 +  mktempf
110 +  echo "dn: $_ENTRY" > "$_TMPFILE" || end_die "Error writing to temporary file $_TMPFILE"
111 +
112 +  # Display entry
113 +  echo "# About to modify the following entry :"
114 +  _ldapsearch "$_ENTRY"
115 +
116 +  # Edit entry
117 +  echo "# Enter your modifications here, end with CTRL-D."
118 +  echo "dn: $_ENTRY"
119 +  cat >> "$_TMPFILE" || end_die "Error writing to temporary file $_TMPFILE"
120 +
121 +  # Send modifications
122 +  cat "$_TMPFILE" | _utf8encode | _ldapmodify
123 +else
124 +  # Action = second argument
125 +  _ACTION="$2"
126 +
127 +  # Field = third argument
128 +  _FIELD="$3"
129 +
130 +  # Value = fourth argument
131 +  _VALUE="$4"
132 +
133 +  # Use template if necessary
134 +  if [ -n "$UMTEMPLATE" ] && [ -r "$UMTEMPLATE" ]
135 +  then
136 +    _getldif="cat $UMTEMPLATE"
137 +  else
138 +    _getldif="_extractldif 2"
139 +  fi
140 +
141 +  # Modify user in LDAP
142 +  $_getldif | _filterldif | _utf8encode | _ldapmodify
143 +fi
144  
145 -# Send modifications
146 -cat "$_TMPFILE" | _utf8encode | _ldapmodify
147  if [ $? -ne 0 ]
148  then
149    reltempf
150 @@ -55,3 +84,9 @@ then
151  fi
152  reltempf
153  end_ok "Successfully modified user entry $_ENTRY in LDAP"
154 +
155 +# Ldif template ##################################
156 +##dn: uid=<user>,<usuffix>,<suffix>
157 +##changeType: modify
158 +##<action>: <field>
159 +##<field>: <value>
160 Index: ldapscripts-2.0.8/lib/runtime
161 ===================================================================
162 --- ldapscripts-2.0.8.orig/lib/runtime
163 +++ ldapscripts-2.0.8/lib/runtime
164 @@ -344,6 +344,9 @@ s|<msuffix>|$MSUFFIX|g
165  s|<_msuffix>|$_MSUFFIX|g
166  s|<gsuffix>|$GSUFFIX|g
167  s|<_gsuffix>|$_GSUFFIX|g
168 +s|<action>|$_ACTION|g
169 +s|<field>|$_FIELD|g
170 +s|<value>|$_VALUE|g
171  EOF
172  
173    # Use it
174 Index: ldapscripts-2.0.8/Makefile
175 ===================================================================
176 --- ldapscripts-2.0.8.orig/Makefile
177 +++ ldapscripts-2.0.8/Makefile
178 @@ -37,11 +37,11 @@ LIBDIR = $(PREFIX)/lib/$(NAME)
179  RUNFILE = runtime
180  ETCFILE = ldapscripts.conf
181  PWDFILE = ldapscripts.passwd
182 -SBINFILES =    ldapdeletemachine ldapmodifygroup ldapsetpasswd lsldap ldapadduser \
183 +SBINFILES =    ldapdeletemachine ldapmodifygroup ldapsetpasswd lsldap ldapadduser ldapaddsudo \
184                         ldapdeleteuser ldapsetprimarygroup ldapfinger ldapid ldapgid ldapmodifymachine \
185                         ldaprenamegroup ldapaddgroup ldapaddusertogroup ldapdeleteuserfromgroup \
186                         ldapinit ldapmodifyuser ldaprenamemachine ldapaddmachine ldapdeletegroup \
187 -                       ldaprenameuser
188 +                       ldaprenameuser ldapmodifysudo
189  MAN1FILES =    ldapdeletemachine.1 ldapmodifymachine.1 ldaprenamemachine.1 ldapadduser.1 \
190                         ldapdeleteuserfromgroup.1 ldapfinger.1 ldapid.1 ldapgid.1 ldapmodifyuser.1 lsldap.1 \
191                         ldapaddusertogroup.1 ldaprenameuser.1 ldapinit.1 ldapsetpasswd.1 ldapaddgroup.1 \
192 Index: ldapscripts-2.0.8/sbin/ldapmodifysudo
193 ===================================================================
194 --- /dev/null
195 +++ ldapscripts-2.0.8/sbin/ldapmodifysudo
196 @@ -0,0 +1,93 @@
197 +#!/bin/sh
198 +
199 +#  ldapmodifyuser : modifies a sudo entry in an LDAP directory
200 +
201 +#  Copyright (C) 2007-2013 Ganaël LAPLANCHE
202 +#  Copyright (C) 2014 Stephen Crooks
203 +#
204 +#  This program is free software; you can redistribute it and/or
205 +#  modify it under the terms of the GNU General Public License
206 +#  as published by the Free Software Foundation; either version 2
207 +#  of the License, or (at your option) any later version.
208 +#
209 +#  This program is distributed in the hope that it will be useful,
210 +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
211 +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
212 +#  GNU General Public License for more details.
213 +#
214 +#  You should have received a copy of the GNU General Public License
215 +#  along with this program; if not, write to the Free Software
216 +#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
217 +#  USA.
218 +
219 +if [ "$1" = "-h" ] || [ "$1" = "--help" ] || \
220 +   [[ "$2" != "add" && "$2" != "replace" && "$2" != "delete" ]] || \
221 +   [ "$#" -ne 4 ]
222 +then
223 +  echo "Usage : $0 <username | uid> [<add | replace | delete> <field> <value>]"
224 +  exit 1
225 +fi
226 +
227 +# Source runtime file
228 +_RUNTIMEFILE="/usr/lib/ldapscripts/runtime"
229 +. "$_RUNTIMEFILE"
230 +
231 +# Find username : $1 must exist in LDAP !
232 +_findentry "$SUFFIX" "(&(objectClass=sudoRole)(|(cn=$1)(sudoUser=$1)))"
233 +[ -z "$_ENTRY" ] && end_die "Sudo user $1 not found in LDAP"
234 +
235 +# Username = first argument
236 +_USER="$1"
237 +
238 +if [ "$#" -eq 1 ]
239 +then
240 +  # Allocate and create temp file
241 +  mktempf
242 +  echo "dn: $_ENTRY" > "$_TMPFILE" || end_die "Error writing to temporary file $_TMPFILE"
243 +
244 +  # Display entry
245 +  echo "# About to modify the following entry :"
246 +  _ldapsearch "$_ENTRY"
247 +
248 +  # Edit entry
249 +  echo "# Enter your modifications here, end with CTRL-D."
250 +  echo "dn: $_ENTRY"
251 +  cat >> "$_TMPFILE" || end_die "Error writing to temporary file $_TMPFILE"
252 +
253 +  # Send modifications
254 +  cat "$_TMPFILE" | _utf8encode | _ldapmodify
255 +else
256 +  # Action = second argument
257 +  _ACTION="$2"
258 +
259 +  # Field = third argument
260 +  _FIELD="$3"
261 +
262 +  # Value = fourth argument
263 +  _VALUE="$4"
264 +
265 +  # Use template if necessary
266 +  if [ -n "$SMTEMPLATE" ] && [ -r "$SMTEMPLATE" ]
267 +  then
268 +    _getldif="cat $SMTEMPLATE"
269 +  else
270 +    _getldif="_extractldif 2"
271 +  fi
272 +
273 +  # Modify user in LDAP
274 +  $_getldif | _filterldif | _utf8encode | _ldapmodify
275 +fi
276 +
277 +if [ $? -ne 0 ]
278 +then
279 +  reltempf
280 +  end_die "Error modifying sudo entry $_ENTRY in LDAP"
281 +fi
282 +reltempf
283 +end_ok "Successfully modified sudo entry $_ENTRY in LDAP"
284 +
285 +# Ldif template ##################################
286 +##dn: cn=<user>,ou=SUDOers,<suffix>
287 +##changeType: modify
288 +##<action>: <field>
289 +##<field>: <value>