kdesu: remove irrelevant kdesud daemon path check

is was (most likely) for platforms that are no longer supported,
also a few identation corrections have been made
This commit is contained in:
Ivailo Monev 2015-10-14 20:46:12 +03:00
parent 587dfedf8e
commit efa6eb3caf

View file

@ -50,7 +50,7 @@ public:
#ifndef SUN_LEN #ifndef SUN_LEN
#define SUN_LEN(ptr) ((socklen_t) (((struct sockaddr_un *) 0)->sun_path) \ #define SUN_LEN(ptr) ((socklen_t) (((struct sockaddr_un *) 0)->sun_path) \
+ strlen ((ptr)->sun_path)) + strlen ((ptr)->sun_path))
#endif #endif
KDEsuClient::KDEsuClient() KDEsuClient::KDEsuClient()
@ -81,25 +81,25 @@ KDEsuClient::KDEsuClient()
KDEsuClient::~KDEsuClient() KDEsuClient::~KDEsuClient()
{ {
if (d->sockfd >= 0) if (d->sockfd >= 0)
close(d->sockfd); close(d->sockfd);
delete d; delete d;
} }
int KDEsuClient::connect() int KDEsuClient::connect()
{ {
if (d->sockfd >= 0) if (d->sockfd >= 0)
close(d->sockfd); close(d->sockfd);
if (access(d->sock, R_OK|W_OK)) if (access(d->sock, R_OK|W_OK))
{ {
d->sockfd = -1; d->sockfd = -1;
return -1; return -1;
} }
d->sockfd = socket(PF_UNIX, SOCK_STREAM, 0); d->sockfd = socket(PF_UNIX, SOCK_STREAM, 0);
if (d->sockfd < 0) if (d->sockfd < 0)
{ {
kWarning(kdesuDebugArea()) << "socket():" << perror; kWarning(kdesuDebugArea()) << "socket():" << perror;
return -1; return -1;
} }
struct sockaddr_un addr; struct sockaddr_un addr;
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
@ -108,8 +108,8 @@ int KDEsuClient::connect()
if (::connect(d->sockfd, (struct sockaddr *) &addr, SUN_LEN(&addr)) < 0) if (::connect(d->sockfd, (struct sockaddr *) &addr, SUN_LEN(&addr)) < 0)
{ {
kWarning(kdesuDebugArea()) << "connect():" << perror; kWarning(kdesuDebugArea()) << "connect():" << perror;
close(d->sockfd); d->sockfd = -1; close(d->sockfd); d->sockfd = -1;
return -1; return -1;
} }
#if !defined(SO_PEERCRED) || !defined(HAVE_STRUCT_UCRED) #if !defined(SO_PEERCRED) || !defined(HAVE_STRUCT_UCRED)
@ -197,26 +197,26 @@ QByteArray KDEsuClient::escape(const QByteArray &str)
int KDEsuClient::command(const QByteArray &cmd, QByteArray *result) int KDEsuClient::command(const QByteArray &cmd, QByteArray *result)
{ {
if (d->sockfd < 0) if (d->sockfd < 0)
return -1; return -1;
if (send(d->sockfd, cmd, cmd.length(), 0) != (int) cmd.length()) if (send(d->sockfd, cmd, cmd.length(), 0) != (int) cmd.length())
return -1; return -1;
char buf[1024]; char buf[1024];
int nbytes = recv(d->sockfd, buf, 1023, 0); int nbytes = recv(d->sockfd, buf, 1023, 0);
if (nbytes <= 0) if (nbytes <= 0)
{ {
kWarning(kdesuDebugArea()) << "no reply from daemon."; kWarning(kdesuDebugArea()) << "no reply from daemon.";
return -1; return -1;
} }
buf[nbytes] = '\000'; buf[nbytes] = '\000';
QByteArray reply = buf; QByteArray reply = buf;
if (reply.left(2) != "OK") if (reply.left(2) != "OK")
return -1; return -1;
if (result) if (result)
*result = reply.mid(3, reply.length()-4); *result = reply.mid(3, reply.length()-4);
return 0; return 0;
} }
@ -399,13 +399,11 @@ int KDEsuClient::stopServer()
static QString findDaemon() static QString findDaemon()
{ {
QString daemon = KStandardDirs::locate("bin", "kdesud"); const QString daemon = KStandardDirs::locate("bin", "kdesud");
if (daemon.isEmpty()) // if not in KDEDIRS, rely on PATH
daemon = KStandardDirs::findExe("kdesud");
if (daemon.isEmpty()) if (daemon.isEmpty())
{ {
kWarning(kdesuDebugArea()) << "daemon not found."; kWarning(kdesuDebugArea()) << "daemon not found.";
} }
return daemon; return daemon;
} }
@ -420,8 +418,8 @@ bool KDEsuClient::isServerSGID()
KDE_struct_stat sbuf; KDE_struct_stat sbuf;
if (KDE::stat(d->daemon, &sbuf) < 0) if (KDE::stat(d->daemon, &sbuf) < 0)
{ {
kWarning(kdesuDebugArea()) << "stat():" << perror; kWarning(kdesuDebugArea()) << "stat():" << perror;
return false; return false;
} }
return (sbuf.st_mode & S_ISGID); return (sbuf.st_mode & S_ISGID);
} }