aboutsummaryrefslogtreecommitdiff
path: root/apps/xhost/xhost.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/xhost/xhost.c')
-rw-r--r--apps/xhost/xhost.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/apps/xhost/xhost.c b/apps/xhost/xhost.c
index 5724e945e..6f803c002 100644
--- a/apps/xhost/xhost.c
+++ b/apps/xhost/xhost.c
@@ -143,7 +143,7 @@ extern int getdomainname(char *name, size_t len);
#endif
static int change_host(Display *dpy, char *name, Bool add);
-static char *get_hostname(XHostAddress *ha);
+static const char *get_hostname(XHostAddress *ha);
static int local_xerror(Display *dpy, XErrorEvent *rep);
#ifdef RETSIGTYPE /* autoconf AC_TYPE_SIGNAL */
@@ -210,7 +210,7 @@ main(int argc, char *argv[])
{
register char *arg;
int i, nhosts = 0;
- char *hostname;
+ const char *hostname;
int nfailed = 0;
XHostAddress *list;
Bool enabled = False;
@@ -223,6 +223,11 @@ main(int argc, char *argv[])
ProgramName = argv[0];
+ if (argc == 2 && !strcmp(argv[1], "-help")) {
+ fprintf(stderr, "usage: %s [[+-]hostname ...]\n", argv[0]);
+ exit(1);
+ }
+
if ((dpy = XOpenDisplay(NULL)) == NULL) {
fprintf(stderr, "%s: unable to open display \"%s\"\n",
ProgramName, XDisplayName (NULL));
@@ -291,11 +296,6 @@ main(int argc, char *argv[])
exit(0);
}
- if (argc == 2 && !strcmp(argv[1], "-help")) {
- fprintf(stderr, "usage: %s [[+-]hostname ...]\n", argv[0]);
- exit(1);
- }
-
for (i = 1; i < argc; i++) {
arg = argv[i];
if (*arg == '-') {
@@ -365,8 +365,8 @@ change_host(Display *dpy, char *name, Bool add)
struct nodeent *np;
static struct dn_naddr dnaddr;
#endif /* DNETCONN */
- static char *add_msg = "being added to access control list";
- static char *remove_msg = "being removed from access control list";
+ static const char *add_msg = "being added to access control list";
+ static const char *remove_msg = "being removed from access control list";
namelen = strlen(name);
if ((lname = (char *)malloc(namelen+1)) == NULL) {
@@ -460,7 +460,7 @@ change_host(Display *dpy, char *name, Bool add)
if (family == FamilyServerInterpreted) {
XServerInterpretedAddress siaddr;
- int namelen;
+ int rc;
cp = strchr(name, ':');
if (cp == NULL || cp == name) {
@@ -469,24 +469,20 @@ change_host(Display *dpy, char *name, Bool add)
ProgramName, name);
return 0;
}
+ siaddr.type = name;
+ siaddr.typelength = cp - name;
+ siaddr.value = ++cp;
+ siaddr.valuelength = strlen(cp);
ha.family = FamilyServerInterpreted;
ha.address = (char *) &siaddr;
- namelen = strlen(name);
- siaddr.type = malloc(namelen);
- if (siaddr.type == NULL) {
- return 0;
- }
- memcpy(siaddr.type, name, namelen);
- siaddr.typelength = cp - name;
- siaddr.type[siaddr.typelength] = '\0';
- siaddr.value = siaddr.type + siaddr.typelength + 1;
- siaddr.valuelength = namelen - (siaddr.typelength + 1);
if (add)
- XAddHost(dpy, &ha);
+ rc = XAddHost(dpy, &ha);
else
- XRemoveHost(dpy, &ha);
- free(siaddr.type);
- printf( "%s %s\n", name, add ? add_msg : remove_msg);
+ rc = XRemoveHost(dpy, &ha);
+ printf( "%s %s%s\n", name, rc == 1 ? "" : "failed when ",
+ add ? add_msg : remove_msg);
+ if (rc != 1)
+ return 0;
return 1;
}
@@ -740,7 +736,7 @@ change_host(Display *dpy, char *name, Bool add)
jmp_buf env;
#endif
-static char *
+static const char *
get_hostname(XHostAddress *ha)
{
#if (defined(TCPCONN) || defined(STREAMSCONN)) && \