我现在正在查看 wininetd 的来源:http://4coder.org/cc-source-code/27/wininetd-0.7/wininetd.c.html ,第 408 行。 CreateProcessAsUserA() 参数似乎很奇怪:lpEnvironment , si.hStdInput 等在调用 ImpersonateLoggedOnUser() 之后被填充,从而创建了不需要的代码重复。
它有什么特殊含义吗?例如,影响句柄继承或破坏安全性?
if (!ImpersonateLoggedOnUser(husr)) {
winet_log(WINET_LOG_ERROR, "[%s] unable to impersonate user: user='%s' err='%s'\n",
WINET_APPNAME, pm->user, emsg = winet_get_syserror());
free(emsg);
CloseHandle(husr);
return -1;
}
if (winet_create_stdhandles(asock, &si.hStdInput, &si.hStdOutput, &si.hStdError) < 0) {
RevertToSelf();
CloseHandle(husr);
return -1;
}
if (!(env = winet_prepare_env(pm, asock, saddr))) {
RevertToSelf();
CloseHandle(husr);
CloseHandle(si.hStdError);
CloseHandle(si.hStdOutput);
CloseHandle(si.hStdInput);
return -1;
}
if (!CreateProcessAsUserA(husr, NULL, pm->cmdline, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS,
env, NULL, &si, &pi)) {
winet_log(WINET_LOG_ERROR, "[%s] unable to create process as user: cmdln='%s' user='%s' err='%s'\n",
WINET_APPNAME, pm->cmdline, pm->user, emsg = winet_get_syserror());
free(emsg);
FreeEnvironmentStrings(env);
RevertToSelf();
CloseHandle(husr);
CloseHandle(si.hStdError);
CloseHandle(si.hStdOutput);
CloseHandle(si.hStdInput);
return -1;
}
RevertToSelf();
CloseHandle(husr);