mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
misc: Reformat ssh_get_user_home_dir and ssh_file_readaccess_ok
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
49
src/misc.c
49
src/misc.c
@@ -213,39 +213,42 @@ int ssh_is_ipaddr(const char *str) {
|
|||||||
#define NSS_BUFLEN_PASSWD 4096
|
#define NSS_BUFLEN_PASSWD 4096
|
||||||
#endif /* NSS_BUFLEN_PASSWD */
|
#endif /* NSS_BUFLEN_PASSWD */
|
||||||
|
|
||||||
char *ssh_get_user_home_dir(void) {
|
char *ssh_get_user_home_dir(void)
|
||||||
char *szPath = NULL;
|
{
|
||||||
struct passwd pwd;
|
char *szPath = NULL;
|
||||||
struct passwd *pwdbuf;
|
struct passwd pwd;
|
||||||
char buf[NSS_BUFLEN_PASSWD] = {0};
|
struct passwd *pwdbuf;
|
||||||
int rc;
|
char buf[NSS_BUFLEN_PASSWD] = {0};
|
||||||
|
int rc;
|
||||||
|
|
||||||
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
|
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
szPath = getenv("HOME");
|
szPath = getenv("HOME");
|
||||||
if (szPath == NULL) {
|
if (szPath == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
snprintf(buf, sizeof(buf), "%s", szPath);
|
snprintf(buf, sizeof(buf), "%s", szPath);
|
||||||
|
|
||||||
return strdup(buf);
|
return strdup(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
szPath = strdup(pwd.pw_dir);
|
szPath = strdup(pwd.pw_dir);
|
||||||
|
|
||||||
return szPath;
|
return szPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we have read access on file */
|
/* we have read access on file */
|
||||||
int ssh_file_readaccess_ok(const char *file) {
|
int ssh_file_readaccess_ok(const char *file)
|
||||||
if (access(file, R_OK) < 0) {
|
{
|
||||||
return 0;
|
if (access(file, R_OK) < 0) {
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ssh_get_local_username(void) {
|
char *ssh_get_local_username(void)
|
||||||
|
{
|
||||||
struct passwd pwd;
|
struct passwd pwd;
|
||||||
struct passwd *pwdbuf;
|
struct passwd *pwdbuf;
|
||||||
char buf[NSS_BUFLEN_PASSWD];
|
char buf[NSS_BUFLEN_PASSWD];
|
||||||
|
|||||||
Reference in New Issue
Block a user