Fix safety annotation issues.

This commit is contained in:
Sönke Ludwig 2016-10-04 17:51:49 +02:00
parent 1c2850f99f
commit 930ba5c3de

View file

@ -87,7 +87,7 @@ version (Windows)
*/ */
int runApplication(string[]* args_out = null) int runApplication(string[]* args_out = null)
@safe { @safe {
try if (!finalizeCommandLineOptions()) return 0; try if (!() @trusted { return finalizeCommandLineOptions(); } () ) return 0;
catch (Exception e) { catch (Exception e) {
logDiagnostic("Error processing command line: %s", e.msg); logDiagnostic("Error processing command line: %s", e.msg);
return 1; return 1;
@ -942,7 +942,7 @@ void disableDefaultSignalHandlers()
system log files). system log files).
*/ */
void lowerPrivileges(string uname, string gname) void lowerPrivileges(string uname, string gname)
{ @safe {
if (!isRoot()) return; if (!isRoot()) return;
if (uname != "" || gname != "") { if (uname != "" || gname != "") {
static bool tryParse(T)(string s, out T n) static bool tryParse(T)(string s, out T n)
@ -961,7 +961,7 @@ void lowerPrivileges(string uname, string gname)
// ditto // ditto
void lowerPrivileges() void lowerPrivileges()
{ @safe {
lowerPrivileges(s_privilegeLoweringUserName, s_privilegeLoweringGroupName); lowerPrivileges(s_privilegeLoweringUserName, s_privilegeLoweringGroupName);
} }
@ -1466,10 +1466,10 @@ nothrow {
version(Posix) version(Posix)
{ {
private bool isRoot() { return geteuid() == 0; } private bool isRoot() @trusted { return geteuid() == 0; }
private void setUID(int uid, int gid) private void setUID(int uid, int gid)
{ @trusted {
logInfo("Lowering privileges to uid=%d, gid=%d...", uid, gid); logInfo("Lowering privileges to uid=%d, gid=%d...", uid, gid);
if (gid >= 0) { if (gid >= 0) {
enforce(getgrgid(gid) !is null, "Invalid group id!"); enforce(getgrgid(gid) !is null, "Invalid group id!");
@ -1483,34 +1483,34 @@ version(Posix)
} }
private int getUID(string name) private int getUID(string name)
{ @trusted {
auto pw = getpwnam(name.toStringz()); auto pw = getpwnam(name.toStringz());
enforce(pw !is null, "Unknown user name: "~name); enforce(pw !is null, "Unknown user name: "~name);
return pw.pw_uid; return pw.pw_uid;
} }
private int getGID(string name) private int getGID(string name)
{ @trusted {
auto gr = getgrnam(name.toStringz()); auto gr = getgrnam(name.toStringz());
enforce(gr !is null, "Unknown group name: "~name); enforce(gr !is null, "Unknown group name: "~name);
return gr.gr_gid; return gr.gr_gid;
} }
} else version(Windows){ } else version(Windows){
private bool isRoot() { return false; } private bool isRoot() @safe { return false; }
private void setUID(int uid, int gid) private void setUID(int uid, int gid)
{ @safe {
enforce(false, "UID/GID not supported on Windows."); enforce(false, "UID/GID not supported on Windows.");
} }
private int getUID(string name) private int getUID(string name)
{ @safe {
enforce(false, "Privilege lowering not supported on Windows."); enforce(false, "Privilege lowering not supported on Windows.");
assert(false); assert(false);
} }
private int getGID(string name) private int getGID(string name)
{ @safe {
enforce(false, "Privilege lowering not supported on Windows."); enforce(false, "Privilege lowering not supported on Windows.");
assert(false); assert(false);
} }