Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check return code when creating ncdns service #73

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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