source: filezilla/trunk/fuentes/data/UAC.nsh @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 8.5 KB
Line 
1/*** UAC Plug-in ***
2
3Interactive User (MediumIL)        Admin user (HighIL)
4***[Setup.exe]*************      ***[Setup.exe]**************
5*                         *      *                          *
6* +++[.OnInit]+++++++++++ *      * +++[.OnInit]++++++++++++ *
7* + UAC_RunElevated >---+-+----> * +                      + *
8* + NSIS.Quit           + *      * +                      + *
9* +++++++++++++++++++++++ *      * ++++++++++++++++++++++++ *
10*                         *      *                          *
11*                         *      *                          *
12* +++[Section]+++++++++++ *      * +++[Section]++++++++++++ *
13* +                     + *   /--+-+-<UAC_AsUser_ExecShell+ *
14* +++++++++++++++++++++++ *   |  * ++++++++++++++++++++++++ *
15*                         *   |  *                          *
16*  Win32.ShellExecute <---+--/   *                          *
17*                         *      *                          *
18***************************      ****************************
19
20*/
21
22!ifndef UAC_HDR__INC
23!verbose push
24!verbose 3
25!ifndef UAC_VERBOSE 
26        !define UAC_VERBOSE 3
27!endif
28!verbose ${UAC_VERBOSE}
29
30!define UAC_HDR__INC 0x00020400 ;MMmmbbrr
31
32!include LogicLib.nsh
33
34
35
36/* UAC_RunElevated
37**
38** Starts the elevation operation.
39**
40** Return values:
41**
42** $0: Win32 error code (0 on success, 1223 if user aborted elevation dialog, anything else should be treated as a fatal error)
43** $1: If $0==0:
44**     0 UAC is not supported by the OS
45**     1 Started a elevated child process, the current process should act like a wrapper (Call Quit without any further processing)
46**     2 The process is already running @ HighIL (Member of admin group)
47**     3 You should call RunElevated again (This can happen if a user without admin priv. is used in the runas dialog)
48** $2: If $0==0 && $1==1: ExitCode of the elevated fork process (The NSIS errlvl is also set)
49** $3: If $0==0: 1 if the user is a member of the admin group or 0 otherwise
50**/
51!macro UAC_RunElevated
52UAC::_ 0
53!macroend
54!macro UAC_PageElevation_RunElevated
55UAC::_ 0
56!macroend
57/*!macro UAC_OnInitElevation_RunElevated
58UAC::_ 0
59!macroend
60!macro UAC_OnInitElevation_OnGuiInit
61!macroend*/
62
63
64
65/* UAC_GetIntegrityLevel <NSISVar:Output | "s">
66**
67** Get integrity level of current process
68**
69**/
70!macro UAC_GetIntegrityLevel outvar
71UAC::_ 6
72!if "${outvar}" != "s"
73        Pop ${outvar}
74!endif
75!macroend
76
77
78
79/* UAC_IsAdmin
80**
81** Is the current process running with administrator privileges? Result in $0
82**
83** ${If} ${UAC_IsAdmin} ...
84**
85**/
86!macro UAC_IsAdmin
87UAC::_ 2
88!macroend
89!define UAC_IsAdmin `"" UAC_IsAdmin ""`
90!macro _UAC_IsAdmin _a _b _t _f
91!insertmacro _UAC_MakeLL_Cmp _!= 0 2s
92!macroend
93
94
95
96/* UAC_IsInnerInstance
97**
98** Does the current process have a NSIS/UAC parent process that is part of the elevation operation?
99**
100** ${If} ${UAC_IsInnerInstance} ...
101**
102**/
103!macro UAC_IsInnerInstance
104UAC::_ 3
105!macroend
106!define UAC_IsInnerInstance `"" UAC_IsInnerInstance ""`
107!macro _UAC_IsInnerInstance _a _b _t _f
108!insertmacro _UAC_MakeLL_Cmp _!= 0 3s
109!macroend
110
111
112
113/* UAC_PageElevation_OnInit, UAC_PageElevation_OnGuiInit,
114**
115** Helper macros for elevation on a custom elevation page, see the DualMode example for more information.
116**
117**/
118!macro UAC_Notify_OnGuiInit
119UAC::_ 4
120!macroend
121!macro UAC_PageElevation_OnGuiInit
122!insertmacro UAC_Notify_OnGuiInit
123!macroend
124!macro UAC_PageElevation_OnInit
125UAC::_ 5
126${IfThen} ${Errors} ${|} Quit ${|}
127!macroend
128
129
130
131/* UAC_AsUser_Call <Function|Label> <NSISAddressName> <UAC_* flags>
132**
133** Calls a function or label in the user process instance.
134** All the UAC_AsUser_* macros use this helper macro.
135**
136**/
137!define UAC_SYNCREGISTERS 0x1
138;define UAC_SYNCSTACK     0x2
139!define UAC_SYNCOUTDIR    0x4
140!define UAC_SYNCINSTDIR   0x8
141;define UAC_CLEARERRFLAG  0x10
142!macro UAC_AsUser_Call type name flags
143push $0
144Get${type}Address $0 ${name}
145!verbose push
146!verbose ${UAC_VERBOSE}
147!insertmacro _UAC_ParseDefineFlagsToInt _UAC_AsUser_Call__flags ${flags}
148!verbose pop
149StrCpy $0 "1$0:${_UAC_AsUser_Call__flags}"
150!undef _UAC_AsUser_Call__flags
151Exch $0
152UAC::_
153!macroend
154
155
156
157/*
158** UAC_AsUser_GetSection <Flags|InstTypes|Size|Text> <SectionIndex> <NSISVar:Output>
159*/
160!macro UAC_AsUser_GetSection secprop secidx outvar
161!insertmacro _UAC_AsUser_GenOp ${outvar} SectionGet${secprop} ${secidx} ""
162!macroend
163
164
165
166/*
167** UAC_AsUser_GetGlobalVar <NSISVar:SourceAndOutput>
168** UAC_AsUser_GetGlobal <NSISVar:Output> <NSISVar:Source>
169*/
170!macro UAC_AsUser_GetGlobalVar var
171!insertmacro _UAC_AsUser_GenOp ${var} StrCpy "" ${var}
172!macroend
173!macro UAC_AsUser_GetGlobal outvar srcvar
174!insertmacro _UAC_AsUser_GenOp ${outvar} StrCpy "" ${srcvar}
175!macroend
176
177
178
179/*
180** UAC_AsUser_ExecShell <Verb> <ApplicationOrFile> <Parameters> <Working Directory> <SW_*>
181**
182** Call ExecShell in the user process instance.
183**
184*/
185!macro UAC_AsUser_ExecShell verb command params workdir show
186!insertmacro _UAC_IncL
187goto _UAC_L_E_${__UAC_L}
188_UAC_L_F_${__UAC_L}:
189ExecShell "${verb}" "${command}" '${params}' ${show}
190return
191_UAC_L_E_${__UAC_L}:
192!if "${workdir}" != ""
193        push $outdir
194        SetOutPath "${workdir}"
195!endif
196!insertmacro UAC_AsUser_Call Label _UAC_L_F_${__UAC_L} ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR} #|${UAC_CLEARERRFLAG}
197!if "${workdir}" != ""
198        pop $outdir 
199        SetOutPath $outdir
200!endif
201!macroend
202
203
204
205!macro _UAC_MakeLL_Cmp cmpop cmp pluginparams
206!insertmacro _LOGICLIB_TEMP
207UAC::_ ${pluginparams}
208pop $_LOGICLIB_TEMP
209!insertmacro ${cmpop} $_LOGICLIB_TEMP ${cmp} `${_t}` `${_f}`
210!macroend
211!macro _UAC_definemath def val1 op val2
212!define /math _UAC_definemath "${val1}" ${op} ${val2}
213!ifdef ${def}
214        !undef ${def}
215!endif
216!define ${def} "${_UAC_definemath}"
217!undef _UAC_definemath
218!macroend
219!macro _UAC_ParseDefineFlags_orin parse outflags
220!searchparse /noerrors ${${parse}} "" _UAC_ParseDefineFlags_orin_f1 "|" _UAC_ParseDefineFlags_orin_f2
221!define _UAC_ParseDefineFlags_orin_this ${_UAC_ParseDefineFlags_orin_f1}
222!undef ${parse}
223!define ${parse} ${_UAC_ParseDefineFlags_orin_f2}
224!define _UAC_ParseDefineFlags_orin_saveout ${${outflags}}
225!undef ${outflags}
226!define /math ${outflags} "${_UAC_ParseDefineFlags_orin_saveout}" | "${_UAC_ParseDefineFlags_orin_this}"
227!undef _UAC_ParseDefineFlags_orin_saveout
228!undef _UAC_ParseDefineFlags_orin_this
229!ifdef _UAC_ParseDefineFlags_orin_f1
230        !undef _UAC_ParseDefineFlags_orin_f1
231        !undef _UAC_ParseDefineFlags_orin_f2
232!endif
233!macroend
234!macro _UAC_ParseDefineFlags_Begin _outdef _in
235!define _UAC_PDF${_outdef}_parse "${_in}"
236!define _UAC_PDF${_outdef}_flags ""
237!define _UAC_PDF${_outdef}_r 0
238!insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags       ;0x1
239!insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags       ;0x2
240!insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags       ;0x4
241!insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags       ;0x8
242!insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags       ;0x10
243!macroend
244!macro _UAC_ParseDefineFlags_End _outdef
245!define ${_outdef} ${_UAC_PDF${_outdef}_r}
246!undef _UAC_PDF${_outdef}_r
247!undef _UAC_PDF${_outdef}_flags
248!undef _UAC_PDF${_outdef}_parse
249!macroend
250!macro _UAC_ParseDefineFlags_IncludeFlag _outdef flag
251!if ${_UAC_PDF${_outdef}_flags} & ${flag}
252        !insertmacro _UAC_definemath _UAC_PDF${_outdef}_r ${_UAC_PDF${_outdef}_r} | ${flag}
253!endif
254!macroend
255!macro _UAC_ParseDefineFlagsToInt _outdef _in
256!insertmacro _UAC_ParseDefineFlags_Begin _UAC_ParseDefineFlagsToInt_tmp "${_in}"
257!define ${_outdef} ${_UAC_PDF_UAC_ParseDefineFlagsToInt_tmp_flags}
258!insertmacro _UAC_ParseDefineFlags_End _UAC_ParseDefineFlagsToInt_tmp
259!undef _UAC_ParseDefineFlagsToInt_tmp
260!macroend
261!macro _UAC_IncL
262!insertmacro _UAC_definemath __UAC_L "${__UAC_L}" + 1
263!macroend
264!macro _UAC_AsUser_GenOp outvar op opparam1 opparam2
265!define _UAC_AUGOGR_ID _UAC_AUGOGR_OP${outvar}${op}${opparam1}${opparam2}
266!ifndef ${_UAC_AUGOGR_ID} ;Has this exact action been done before?
267        !if ${outvar} == $0
268                !define ${_UAC_AUGOGR_ID} $1
269        !else
270                !define ${_UAC_AUGOGR_ID} $0
271        !endif
272        !if "${opparam1}" == ""
273                !define _UAC_AUGOGR_OPP1 ${${_UAC_AUGOGR_ID}}
274                !define _UAC_AUGOGR_OPP2 ${opparam2}
275        !else
276                !define _UAC_AUGOGR_OPP1 ${opparam1}
277                !define _UAC_AUGOGR_OPP2 ${${_UAC_AUGOGR_ID}}
278        !endif 
279        goto ${_UAC_AUGOGR_ID}_C
280        ${_UAC_AUGOGR_ID}_F:
281                ${op} ${_UAC_AUGOGR_OPP1} ${_UAC_AUGOGR_OPP2}
282                return
283        ${_UAC_AUGOGR_ID}_C:
284        !undef _UAC_AUGOGR_OPP1
285        !undef _UAC_AUGOGR_OPP2
286!endif
287push ${${_UAC_AUGOGR_ID}}
288!insertmacro UAC_AsUser_Call Label ${_UAC_AUGOGR_ID}_F ${UAC_SYNCREGISTERS}
289StrCpy ${outvar} ${${_UAC_AUGOGR_ID}}
290pop ${${_UAC_AUGOGR_ID}}
291!undef _UAC_AUGOGR_ID
292!macroend
293
294
295
296!verbose pop
297!endif /* UAC_HDR__INC */
Note: See TracBrowser for help on using the repository browser.