Skip to content

Commit

Permalink
Merge #73: Check return code when creating ncdns service
Browse files Browse the repository at this point in the history
b23fd97 Check return code when creating ncdns service (Jeremy Rand)

Pull request description:

  Refs #71

Top commit has no ACKs.

Tree-SHA512: ddd389a5f97e06792fb9663500af4edcb820d817d0ba59b33d140106db9f068736584649bdfb56ae9cb63d50cdac3bdde8d5444e138b8fdabbe84f05c4a92d2b
  • Loading branch information
JeremyRand committed Feb 11, 2021
2 parents a66287d + b23fd97 commit 447bf92
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ncdns.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ Var /GLOBAL BitcoinJRequirementsMet
Var /GLOBAL BitcoinJRequirementsError
Var /GLOBAL ETLD

Var /GLOBAL ServiceCreateReturnCode
Var /GLOBAL ServiceSidtypeReturnCode
Var /GLOBAL ServiceDescriptionReturnCode
Var /GLOBAL ServicePrivsReturnCode

# PRELAUNCH CHECKS
##############################################################################
!Include WinVer.nsh
Expand Down Expand Up @@ -958,12 +963,36 @@ FunctionEnd
##############################################################################
Function Service
nsExec::ExecToLog 'sc create ncdns binPath= "ncdns.tmp" start= auto error= normal obj= "NT AUTHORITY\LocalService" DisplayName= "ncdns"'
Pop $ServiceCreateReturnCode
${If} $ServiceCreateReturnCode != 0
DetailPrint "Failed to create ncdns service: return code $ServiceCreateReturnCode"
MessageBox "MB_OK|MB_ICONSTOP" "Failed to create ncdns service." /SD IDOK
Abort
${EndIf}
# Use service SID.
nsExec::ExecToLog 'sc sidtype ncdns restricted'
Pop $ServiceSidtypeReturnCode
${If} $ServiceSidtypeReturnCode != 0
DetailPrint "Failed to restrict ncdns service: return code $ServiceSidtypeReturnCode"
MessageBox "MB_OK|MB_ICONSTOP" "Failed to restrict ncdns service." /SD IDOK
Abort
${EndIf}
nsExec::ExecToLog 'sc description ncdns "Namecoin ncdns daemon"'
Pop $ServiceDescriptionReturnCode
${If} $ServiceDescriptionReturnCode != 0
DetailPrint "Failed to set description on ncdns service: return code $ServiceDescriptionReturnCode"
MessageBox "MB_OK|MB_ICONSTOP" "Failed to set description on ncdns service." /SD IDOK
Abort
${EndIf}
# Restrict privileges. 'sc privs' interprets an empty list as meaning no
# privilege restriction... this one seems low-risk.
nsExec::ExecToLog 'sc privs ncdns "SeChangeNotifyPrivilege"'
Pop $ServicePrivsReturnCode
${If} $ServicePrivsReturnCode != 0
DetailPrint "Failed to set privileges on ncdns service: return code $ServicePrivsReturnCode"
MessageBox "MB_OK|MB_ICONSTOP" "Failed to set privileges on ncdns service." /SD IDOK
Abort
${EndIf}
# Set the proper image path manually rather than try to escape it properly
# above.
WriteRegStr HKLM "System\CurrentControlSet\Services\ncdns" "ImagePath" '"$INSTDIR\bin\ncdns.exe" "-conf=$INSTDIR\etc\ncdns.conf"'
Expand Down

0 comments on commit 447bf92

Please sign in to comment.