implement freezero(), use localtime_s() instead of localtime() (#300)
PowerShell/Win32-OpenSSH#1121
This commit is contained in:
parent
8c9c6a0e17
commit
8013f1377b
|
@ -1699,3 +1699,4 @@
|
|||
#define _PATH_SSH_PROGRAM "ssh.exe"
|
||||
#define _PATH_LS "dir"
|
||||
#define FORK_NOT_SUPPORTED 1
|
||||
#define HAVE_FREEZERO
|
|
@ -1,4 +1,5 @@
|
|||
#include "crtheaders.h"
|
||||
#include STDLIB_H
|
||||
|
||||
#define environ _environ
|
||||
#define environ _environ
|
||||
void freezero(void *, size_t);
|
|
@ -1259,7 +1259,7 @@ getusergroups(const char *user, int *ngroups)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
/* allocate memory to hold points to all group names; we double the value
|
||||
/* allocate memory to hold points to all group names; we double the value
|
||||
* in order to account for local groups that we trim the domain qualifier */
|
||||
if ((user_groups = (char**)malloc(sizeof(char*) * group_buf->GroupCount * 2)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
|
@ -1285,42 +1285,42 @@ getusergroups(const char *user, int *ngroups)
|
|||
sub == SECURITY_NT_NON_UNIQUE || sub == SECURITY_BUILTIN_DOMAIN_RID) &&
|
||||
rid != DOMAIN_GROUP_RID_USERS && rid != DOMAIN_ALIAS_RID_USERS) {
|
||||
|
||||
/* lookup the account name for this sid */
|
||||
wchar_t name[GNLEN + 1];
|
||||
DWORD name_len = ARRAYSIZE(name);
|
||||
wchar_t domain[DNLEN + 1];
|
||||
DWORD domain_len = ARRAYSIZE(domain);
|
||||
SID_NAME_USE name_use = 0;
|
||||
if (LookupAccountSidW(NULL, sid, name, &name_len, domain, &domain_len, &name_use) == 0) {
|
||||
errno = ENOENT;
|
||||
debug("%s: LookupAccountSid() failed: %d.", __FUNCTION__, GetLastError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* add group name in netbios\\name format */
|
||||
int current_group = (*ngroups)++;
|
||||
wchar_t formatted_group[DNLEN + 1 + GNLEN + 1];
|
||||
swprintf_s(formatted_group, ARRAYSIZE(formatted_group), L"%s\\%s", domain, name);
|
||||
_wcslwr_s(formatted_group, ARRAYSIZE(formatted_group));
|
||||
debug3("Added group '%ls' for user '%s'.", formatted_group, user);
|
||||
user_groups[current_group] = utf16_to_utf8(formatted_group);
|
||||
if (user_groups[current_group] == NULL) {
|
||||
errno = ENOMEM;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* for local accounts trim the domain qualifier */
|
||||
if (_wcsicmp(computer_name, domain) == 0)
|
||||
{
|
||||
current_group = (*ngroups)++;
|
||||
swprintf_s(formatted_group, ARRAYSIZE(formatted_group), L"%s", name);
|
||||
_wcslwr_s(formatted_group, ARRAYSIZE(formatted_group));
|
||||
debug3("Added group '%ls' for user '%s'.", formatted_group, user);
|
||||
user_groups[current_group] = utf16_to_utf8(formatted_group);
|
||||
if (user_groups[current_group] == NULL) {
|
||||
errno = ENOMEM;
|
||||
goto cleanup;
|
||||
}
|
||||
/* lookup the account name for this sid */
|
||||
wchar_t name[GNLEN + 1];
|
||||
DWORD name_len = ARRAYSIZE(name);
|
||||
wchar_t domain[DNLEN + 1];
|
||||
DWORD domain_len = ARRAYSIZE(domain);
|
||||
SID_NAME_USE name_use = 0;
|
||||
if (LookupAccountSidW(NULL, sid, name, &name_len, domain, &domain_len, &name_use) == 0) {
|
||||
errno = ENOENT;
|
||||
debug("%s: LookupAccountSid() failed: %d.", __FUNCTION__, GetLastError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* add group name in netbios\\name format */
|
||||
int current_group = (*ngroups)++;
|
||||
wchar_t formatted_group[DNLEN + 1 + GNLEN + 1];
|
||||
swprintf_s(formatted_group, ARRAYSIZE(formatted_group), L"%s\\%s", domain, name);
|
||||
_wcslwr_s(formatted_group, ARRAYSIZE(formatted_group));
|
||||
debug3("Added group '%ls' for user '%s'.", formatted_group, user);
|
||||
user_groups[current_group] = utf16_to_utf8(formatted_group);
|
||||
if (user_groups[current_group] == NULL) {
|
||||
errno = ENOMEM;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* for local accounts trim the domain qualifier */
|
||||
if (_wcsicmp(computer_name, domain) == 0)
|
||||
{
|
||||
current_group = (*ngroups)++;
|
||||
swprintf_s(formatted_group, ARRAYSIZE(formatted_group), L"%s", name);
|
||||
_wcslwr_s(formatted_group, ARRAYSIZE(formatted_group));
|
||||
debug3("Added group '%ls' for user '%s'.", formatted_group, user);
|
||||
user_groups[current_group] = utf16_to_utf8(formatted_group);
|
||||
if (user_groups[current_group] == NULL) {
|
||||
errno = ENOMEM;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1555,11 +1555,23 @@ copy_file(char *source, char *destination)
|
|||
struct tm*
|
||||
localtime_r(const time_t *timep, struct tm *result)
|
||||
{
|
||||
struct tm *t = localtime(timep);
|
||||
memcpy(result, t, sizeof(struct tm));
|
||||
struct tm *t = NULL;
|
||||
|
||||
if(!localtime_s(t, timep))
|
||||
memcpy(result, t, sizeof(struct tm));
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void
|
||||
freezero(void *ptr, size_t sz)
|
||||
{
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
explicit_bzero(ptr, sz);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
int
|
||||
chroot(const char *path)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue