in src/common/commonutils/UserUtils.c [57:127]
static int CopyUserEntry(SimplifiedUser* destination, struct passwd* source, OsConfigLogHandle log)
{
int status = 0;
size_t length = 0;
if ((NULL == destination) || (NULL == source))
{
OsConfigLogError(log, "CopyUserEntry: invalid arguments");
return EINVAL;
}
ResetUserEntry(destination);
if (0 < (length = (source->pw_name ? strlen(source->pw_name) : 0)))
{
if (NULL == (destination->username = malloc(length + 1)))
{
OsConfigLogError(log, "CopyUserEntry: out of memory copying pw_name for user %u", source->pw_uid);
status = ENOMEM;
}
else
{
memset(destination->username, 0, length + 1);
memcpy(destination->username, source->pw_name, length);
}
}
if (0 == status)
{
destination->userId = source->pw_uid;
destination->groupId = source->pw_gid;
destination->isRoot = ((0 == destination->userId) && (0 == destination->groupId)) ? true : false;
}
if ((0 == status) && (0 < (length = source->pw_dir ? strlen(source->pw_dir) : 0)))
{
if (NULL == (destination->home = malloc(length + 1)))
{
OsConfigLogError(log, "CopyUserEntry: out of memory copying pw_dir '%s'", source->pw_dir);
status = ENOMEM;
}
else
{
memset(destination->home, 0, length + 1);
memcpy(destination->home, source->pw_dir, length);
}
}
if ((0 == status) && (0 < (length = source->pw_shell ? strlen(source->pw_shell) : 0)))
{
if (NULL == (destination->shell = malloc(length + 1)))
{
OsConfigLogError(log, "CopyUserEntry: out of memory copying pw_shell '%s'", source->pw_shell);
status = ENOMEM;
}
else
{
memset(destination->shell, 0, length + 1);
memcpy(destination->shell, source->pw_shell, length);
}
}
if (0 != status)
{
ResetUserEntry(destination);
}
return status;
}