~ubuntu-branches/ubuntu/precise/xdm/precise

« back to all changes in this revision

Viewing changes to chooser.c

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2011-01-30 00:53:09 UTC
  • mfrom: (9.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110130005309-30mjjyk7div7d494
Tags: 1:1.1.10-3ubuntu1
* Merge from debian unstable.  Remaining changes: (LP: #682196)
  - debian/{rules, xdm.install, local/ubuntu*}:
    + Add Ubuntu graphics and configure xdm to use them by default.
  - debian/patches/ubuntu_no_whiteglass.diff: Don't hardcode
    the default Xcursor theme to whiteglass. Use the Ubuntu
    default x-cursor-theme instead.
* debian/patches/ftbfs_binutils-gold.diff: Fix FTBFS with binutils-gold
  and ld --as-needed. (Closes: #556694)
* Dropped changes, no longer applicable:
  - debian/{xdm.postinst.in, xdm.postrm.in, xdm.preinst.in}

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $XdotOrg: app/xdm/chooser.c,v 1.5 2006/03/11 04:07:00 alanc Exp $
3
 
 * $Xorg: chooser.c,v 1.4 2001/02/09 02:05:40 xorgcvs Exp $
4
2
 *
5
3
Copyright 1990, 1998  The Open Group
6
4
 
27
25
 * Author:  Keith Packard, MIT X Consortium
28
26
 */
29
27
 
30
 
/* $XFree86: xc/programs/xdm/chooser.c,v 3.26 2003/07/18 15:53:28 tsi Exp $ */
31
28
 
32
29
/*
33
30
 * Chooser - display a menu of names and let the user select one
72
69
#include    <ctype.h>
73
70
 
74
71
#ifdef USE_XINERAMA
75
 
#include    <X11/extensions/Xinerama.h>
 
72
# include    <X11/extensions/Xinerama.h>
76
73
#endif
77
74
 
78
75
#if defined(SVR4)
79
 
#include    <sys/sockio.h>
 
76
# include    <sys/sockio.h>
80
77
#endif
81
78
#if defined(SVR4) && defined(PowerMAX_OS)
82
 
#include    <sys/stropts.h>
 
79
# include    <sys/stropts.h>
83
80
#endif
84
81
#if defined(SYSV) && defined(i386)
85
 
#include    <sys/stream.h>
86
 
#ifdef ISC
87
 
#include    <sys/sioctl.h>
88
 
#include    <sys/stropts.h>
89
 
#endif
 
82
# include    <sys/stream.h>
 
83
# ifdef ISC
 
84
#  include    <sys/sioctl.h>
 
85
#  include    <sys/stropts.h>
 
86
# endif
90
87
#endif
91
88
 
92
89
#include    "dm_socket.h"
95
92
 
96
93
#include    <sys/ioctl.h>
97
94
#ifdef STREAMSCONN
98
 
#ifdef WINTCP /* NCR with Wollongong TCP */
99
 
#include    <netinet/ip.h>
100
 
#endif
101
 
#include    <stropts.h>
102
 
#include    <tiuser.h>
103
 
#include    <netconfig.h>
104
 
#include    <netdir.h>
 
95
# ifdef WINTCP /* NCR with Wollongong TCP */
 
96
#  include    <netinet/ip.h>
 
97
# endif
 
98
# include    <stropts.h>
 
99
# include    <tiuser.h>
 
100
# include    <netconfig.h>
 
101
# include    <netdir.h>
105
102
#endif
106
103
 
107
104
#ifdef CSRG_BASED
108
 
#include <sys/param.h>
109
 
#if (BSD >= 199103)
110
 
#define VARIABLE_IFREQ
111
 
#endif
 
105
# include <sys/param.h>
 
106
# if (BSD >= 199103)
 
107
#  define VARIABLE_IFREQ
 
108
# endif
112
109
#endif
113
110
 
114
111
#ifdef XKB
115
 
#include <X11/extensions/XKBbells.h>
 
112
# include <X11/extensions/XKBbells.h>
116
113
#endif
117
114
 
118
115
#define BROADCAST_HOSTNAME  "BROADCAST"
119
116
 
120
117
#ifndef ishexdigit
121
 
#define ishexdigit(c)   (isdigit(c) || ('a' <= (c) && (c) <= 'f'))
 
118
# define ishexdigit(c)  (isdigit(c) || ('a' <= (c) && (c) <= 'f'))
122
119
#endif
123
120
 
124
121
#ifdef hpux
127
124
#  include <net/if.h>
128
125
# endif
129
126
#else
130
 
#ifdef __convex__
131
 
# include <sync/queue.h>
132
 
# include <sync/sema.h>
133
 
#endif
134
 
#include <net/if.h>
 
127
# ifdef __convex__
 
128
#  include <sync/queue.h>
 
129
#  include <sync/sema.h>
 
130
# endif
 
131
# include <net/if.h>
135
132
#endif /* hpux */
136
133
 
137
134
#include    <netdb.h>
224
221
    {
225
222
        ioc.ic_len = ((struct ifconf *) arg)->ifc_len;
226
223
        ioc.ic_dp = ((struct ifconf *) arg)->ifc_buf;
227
 
#ifdef ISC
 
224
# ifdef ISC
228
225
        /* SIOCGIFCONF is somewhat brain damaged on ISC. The argument
229
226
         * buffer must contain the ifconf structure as header. Ifc_req
230
227
         * is also not a pointer but a one element array of ifreq
234
231
         */
235
232
        ((struct ifconf *) ioc.ic_dp)->ifc_len =
236
233
                                         ioc.ic_len - sizeof(struct ifconf);
237
 
#endif
 
234
# endif
238
235
    }
239
236
    else
240
237
    {
243
240
    }
244
241
    ret = ioctl(fd, I_STR, (char *) &ioc);
245
242
    if (ret >= 0 && cmd == SIOCGIFCONF)
246
 
#ifdef SVR4
 
243
# ifdef SVR4
247
244
        ((struct ifconf *) arg)->ifc_len = ioc.ic_len;
248
 
#endif
249
 
#ifdef ISC
 
245
# endif
 
246
# ifdef ISC
250
247
    {
251
248
        ((struct ifconf *) arg)->ifc_len =
252
249
                                 ((struct ifconf *)ioc.ic_dp)->ifc_len;
253
 
        ((struct ifconf *) arg)->ifc_buf = 
 
250
        ((struct ifconf *) arg)->ifc_buf =
254
251
                        (caddr_t)((struct ifconf *)ioc.ic_dp)->ifc_req;
255
252
    }
256
 
#endif
 
253
# endif
257
254
    return(ret);
258
255
}
259
256
#else /* ((SVR4 && !sun && !NCR) || ISC) && SIOCGIFCONF */
260
 
#define ifioctl ioctl
 
257
# define ifioctl ioctl
261
258
#endif /* ((SVR4 && !sun) || ISC) && SIOCGIFCONF */
262
259
 
263
260
 
277
274
            sfd = socketFD;
278
275
#endif
279
276
        if (hosts->type == QUERY)
280
 
            XdmcpFlush (sfd, &directBuffer, 
 
277
            XdmcpFlush (sfd, &directBuffer,
281
278
                        (XdmcpNetaddr) hosts->addr, hosts->addrlen);
282
279
        else
283
 
            XdmcpFlush (sfd, &broadcastBuffer, 
 
280
            XdmcpFlush (sfd, &broadcastBuffer,
284
281
                        (XdmcpNetaddr) hosts->addr, hosts->addrlen);
285
282
    }
286
283
    if (++pingTry < TRIES)
323
320
AddHostname (ARRAY8Ptr hostname, ARRAY8Ptr status, struct sockaddr *addr, int willing)
324
321
{
325
322
    HostName    *new, **names, *name;
326
 
    ARRAY8      hostAddr;
 
323
    ARRAY8      hostAddr = {0, NULL};
327
324
    CARD16      connectionType;
328
325
    int         fulllen;
329
326
 
376
373
                {
377
374
                    struct hostent  *hostent;
378
375
                    char            *host;
379
 
        
 
376
 
380
377
                    hostent = gethostbyaddr ((char *)hostAddr.data, hostAddr.length, addr->sa_family);
381
378
                    if (hostent)
382
379
                    {
416
413
    fulllen = hostname->length;
417
414
    if (fulllen < 30)
418
415
        fulllen = 30;
419
 
    new->fullname = malloc (fulllen + status->length + 10);
 
416
    fulllen += status->length + 10;
 
417
    new->fullname = malloc (fulllen);
420
418
    if (!new->fullname)
421
419
    {
422
420
        new->fullname = "Unknown";
423
421
    }
424
422
    else
425
423
    {
426
 
        sprintf (new->fullname, "%-30.*s %*.*s",
 
424
        snprintf(new->fullname, fulllen, "%-30.*s %*.*s",
427
425
                 hostname->length, hostname->data,
428
426
                 status->length, status->length, status->data);
429
427
    }
483
481
ReceivePacket (XtPointer closure, int *source, XtInputId *id)
484
482
{
485
483
    XdmcpHeader     header;
486
 
    ARRAY8          authenticationName;
487
 
    ARRAY8          hostname;
488
 
    ARRAY8          status;
 
484
    ARRAY8          authenticationName = {0, NULL};
 
485
    ARRAY8          hostname = {0, NULL};
 
486
    ARRAY8          status = {0, NULL};
489
487
    int             saveHostname = 0;
490
488
#if defined(IPv6) && defined(AF_INET6)
491
489
    struct sockaddr_storage addr;
502
500
        return;
503
501
    if (header.version != XDM_PROTOCOL_VERSION)
504
502
        return;
505
 
    hostname.data = NULL;
506
 
    status.data = NULL;
507
 
    authenticationName.data = NULL;
508
503
    switch (header.opcode) {
509
504
    case WILLING:
510
505
        if (XdmcpReadARRAY8 (&buffer, &authenticationName) &&
576
571
 
577
572
/* Handle variable length ifreq in BNR2 and later */
578
573
#ifdef VARIABLE_IFREQ
579
 
#define ifr_size(p) (sizeof (struct ifreq) + \
 
574
# define ifr_size(p) (sizeof (struct ifreq) + \
580
575
                     (p->ifr_addr.sa_len > sizeof (p->ifr_addr) ? \
581
576
                      p->ifr_addr.sa_len - sizeof (p->ifr_addr) : 0))
582
577
#else
583
 
#define ifr_size(p) (sizeof (struct ifreq))
 
578
# define ifr_size(p) (sizeof (struct ifreq))
584
579
#endif
585
580
 
586
581
static void
634
629
        if (ifioctl (socketFD, (int) SIOCGIFCONF, (char *) &ifc) < 0)
635
630
            return;
636
631
 
637
 
#ifdef ISC
638
 
#define IFC_IFC_REQ (struct ifreq *) ifc.ifc_buf
639
 
#else
640
 
#define IFC_IFC_REQ ifc.ifc_req
641
 
#endif
 
632
# ifdef ISC
 
633
#  define IFC_IFC_REQ (struct ifreq *) ifc.ifc_buf
 
634
# else
 
635
#  define IFC_IFC_REQ ifc.ifc_req
 
636
# endif
642
637
 
643
638
        cplim = (char *) IFC_IFC_REQ + ifc.ifc_len;
644
639
 
657
652
#ifdef SIOCGIFBRDADDR
658
653
            {
659
654
                struct ifreq    broad_req;
660
 
    
 
655
 
661
656
                broad_req = *ifr;
662
 
#ifdef WINTCP /* NCR with Wollongong TCP */
 
657
# ifdef WINTCP /* NCR with Wollongong TCP */
663
658
                ioc.ic_cmd = IPIOC_GETIFFLAGS;
664
659
                ioc.ic_timout = 0;
665
660
                ioc.ic_len = sizeof( broad_req );
666
661
                ioc.ic_dp = (char *)&broad_req;
667
662
 
668
663
                if (ioctl (ipfd, I_STR, (char *) &ioc) != -1 &&
669
 
#else /* WINTCP */
 
664
# else /* WINTCP */
670
665
                if (ifioctl (socketFD, SIOCGIFFLAGS, (char *) &broad_req) != -1 &&
671
 
#endif /* WINTCP */
 
666
# endif /* WINTCP */
672
667
                    (broad_req.ifr_flags & IFF_BROADCAST) &&
673
668
                    (broad_req.ifr_flags & IFF_UP)
674
669
                    )
675
670
                {
676
671
                    broad_req = *ifr;
677
 
#ifdef WINTCP /* NCR with Wollongong TCP */
 
672
# ifdef WINTCP /* NCR with Wollongong TCP */
678
673
                    ioc.ic_cmd = IPIOC_GETIFBRDADDR;
679
674
                    ioc.ic_timout = 0;
680
675
                    ioc.ic_len = sizeof( broad_req );
681
676
                    ioc.ic_dp = (char *)&broad_req;
682
677
 
683
678
                    if (ioctl (ipfd, I_STR, (char *) &ioc) != -1)
684
 
#else /* WINTCP */
 
679
# else /* WINTCP */
685
680
                    if (ifioctl (socketFD, SIOCGIFBRDADDR, &broad_req) != -1)
686
 
#endif /* WINTCP */
 
681
# endif /* WINTCP */
687
682
                        broad_addr = broad_req.ifr_addr;
688
683
                    else
689
684
                        continue;
721
716
            struct addrinfo *ai, *nai, hints;
722
717
            bzero(&hints,sizeof(hints));
723
718
            hints.ai_socktype = SOCK_DGRAM;
724
 
            sprintf(sport, "%d", XDM_UDP_PORT);
 
719
            snprintf(sport, sizeof(sport), "%d", XDM_UDP_PORT);
725
720
            if (getaddrinfo(name, sport, &hints, &ai) == 0) {
726
721
                for (nai = ai ; nai != NULL ; nai = nai->ai_next) {
727
 
                    if ((nai->ai_family == AF_INET) || 
 
722
                    if ((nai->ai_family == AF_INET) ||
728
723
                        (nai->ai_family == AF_INET6)) {
729
 
                        if (((nai->ai_family == AF_INET) && 
 
724
                        if (((nai->ai_family == AF_INET) &&
730
725
                          IN_MULTICAST(((struct sockaddr_in *) nai->ai_addr)
731
726
                            ->sin_addr.s_addr))
732
 
                          || ((nai->ai_family == AF_INET6) && 
 
727
                          || ((nai->ai_family == AF_INET6) &&
733
728
                            IN6_IS_ADDR_MULTICAST(
734
729
                                &((struct sockaddr_in6 *) nai->ai_addr)
735
 
                                  ->sin6_addr))) 
 
730
                                  ->sin6_addr)))
736
731
                        {
737
 
                            RegisterHostaddr(nai->ai_addr, nai->ai_addrlen, 
 
732
                            RegisterHostaddr(nai->ai_addr, nai->ai_addrlen,
738
733
                              BROADCAST_QUERY);
739
734
                        } else {
740
 
                            RegisterHostaddr(nai->ai_addr, nai->ai_addrlen, 
 
735
                            RegisterHostaddr(nai->ai_addr, nai->ai_addrlen,
741
736
                              QUERY);
742
737
                        }
743
738
                    }
760
755
            memmove( &in_addr.sin_addr, hostent->h_addr, 4);
761
756
        }
762
757
        in_addr.sin_port = htons (XDM_UDP_PORT);
763
 
#ifdef BSD44SOCKETS
 
758
# ifdef BSD44SOCKETS
764
759
        in_addr.sin_len = sizeof(in_addr);
765
 
#endif
 
760
# endif
766
761
        RegisterHostaddr ((struct sockaddr *)&in_addr, sizeof (in_addr),
767
762
                          QUERY);
768
763
#endif /* IPv6 */
845
840
#else
846
841
    if ((socketFD = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
847
842
        return 0;
848
 
#if defined(IPv6) && defined(AF_INET6)
 
843
# if defined(IPv6) && defined(AF_INET6)
849
844
    socket6FD = socket (AF_INET6, SOCK_DGRAM, 0);
850
 
#endif
 
845
# endif
851
846
#endif
852
847
#ifndef STREAMSCONN
853
 
#ifdef SO_BROADCAST
 
848
# ifdef SO_BROADCAST
854
849
    soopts = 1;
855
850
    if (setsockopt (socketFD, SOL_SOCKET, SO_BROADCAST, (char *)&soopts, sizeof (soopts)) < 0)
856
851
        perror ("setsockopt");
857
 
#endif
858
 
#endif
859
 
    
 
852
# endif
 
853
#endif
 
854
 
860
855
    XtAddInput (socketFD, (XtPointer) XtInputReadMask, ReceivePacket,
861
856
                (XtPointer) &socketFD);
862
857
#if defined(IPv6) && defined(AF_INET6)
910
905
#if defined(IPv6) && defined(AF_INET6)
911
906
        case AF_INET6:
912
907
            bzero(&in6_addr, sizeof(in6_addr));
913
 
#ifdef SIN6_LEN
 
908
# ifdef SIN6_LEN
914
909
            in6_addr.sin6_len = sizeof(in6_addr);
915
 
#endif
 
910
# endif
916
911
            in6_addr.sin6_family = family;
917
912
            memmove( &in6_addr.sin6_port, xdm + 2, 2);
918
913
            memmove( &in6_addr.sin6_addr, xdm + 4, 16);
1005
1000
  (0, 1, 2, 3, 0, 1, 2, 3 ....)
1006
1001
*/
1007
1002
 
1008
 
static int 
 
1003
static int
1009
1004
next_line(unsigned int current, unsigned int size, int event)
1010
1005
{
1011
1006
  switch(event) {
1017
1012
      return (current + 1) % size;
1018
1013
    case XK_Up:
1019
1014
      return (current + size - 1) % size;
1020
 
  }  
 
1015
  }
1021
1016
  return -1;
1022
1017
}
1023
1018
 
1024
 
/* 
 
1019
/*
1025
1020
  Hostselect selects a given chooser line.
1026
1021
  Returns 1 when host is willing and 0 if not
1027
1022
*/
1066
1061
            XawViewportSetCoordinates(viewport, 0,
1067
1062
                                      (liney + lineheight) - portheight);
1068
1063
        }
1069
 
        
 
1064
 
1070
1065
        XtFree((char *) r);
1071
1066
        return 1;
1072
1067
      }
1073
1068
    }
1074
1069
  }
1075
1070
  XtFree((char *) r);
1076
 
  return 0; 
 
1071
  return 0;
1077
1072
}
1078
1073
 
1079
 
/* 
 
1074
/*
1080
1075
  Selectfirst selects the first willing host
1081
1076
  in the chooser list (so you can select a host without
1082
1077
  presence of mouse, but with pressing space or return,
1087
1082
Selectfirst (void)
1088
1083
{
1089
1084
  int line;
1090
 
  
 
1085
 
1091
1086
  for (line = 0; line < NameTableSize; line++)
1092
1087
  {
1093
1088
    if (Hostselect(line))
1094
1089
      return;
1095
 
  }        
 
1090
  }
1096
1091
  return;
1097
1092
}
1098
1093
 
1110
1105
}
1111
1106
 
1112
1107
/*
1113
 
  Setold restores the global int oldentry 
 
1108
  Setold restores the global int oldentry
1114
1109
  when you try to select a host with your mouse
1115
1110
  who is unwilling as follows:
1116
1111
  <Btn1Down>:     Store() Set() CheckWilling() Setold() \n\
1159
1154
  XawListReturnStruct   *r;
1160
1155
 
1161
1156
  XLookupString (&event->xkey, strbuf, sizeof (strbuf),
1162
 
                           &keysym, &compose_status);    
 
1157
                           &keysym, &compose_status);
1163
1158
 
1164
1159
  if (keysym != XK_Up && keysym != XK_Down)
1165
1160
    return;
1166
1161
 
1167
1162
  r = XawListShowCurrent (list);
1168
 
    
 
1163
 
1169
1164
  if (r->list_index == XAW_LIST_NONE)
1170
1165
    Selectfirst();
1171
1166
  else
1187
1182
{
1188
1183
    XawListReturnStruct *r;
1189
1184
    r = XawListShowCurrent (list);
1190
 
    
 
1185
 
1191
1186
    if (r->list_index == XAW_LIST_NONE)
1192
1187
      Selectfirst();
1193
1188
    else
1194
1189
      HostCycle(r->list_index,NameTableSize,event->xbutton.button);
1195
 
    
 
1190
 
1196
1191
    XtFree((char *) r);
1197
1192
    return;
1198
1193
}
1230
1225
{
1231
1226
    XawListReturnStruct *r;
1232
1227
    HostName            *h;
1233
 
    
 
1228
 
1234
1229
    r = XawListShowCurrent (list);
1235
1230
    if (r->list_index != XAW_LIST_NONE) {
1236
1231
        for (h = hostNamedb; h; h = h->next)
1265
1260
    { "KeySwitch",    Switch_Key },
1266
1261
    { "BtnSwitch",    Switch_Btn },
1267
1262
    { "Store",        Storeold },
1268
 
    { "Setold",       Setold },    
 
1263
    { "Setold",       Setold },
1269
1264
};
1270
1265
 
1271
1266
int
1314
1309
    {
1315
1310
        x = (Position)(screens[0].x_org + (screens[0].width - width) / 2);
1316
1311
        y = (Position)(screens[0].y_org + (screens[0].height - height) / 3);
1317
 
        
 
1312
 
1318
1313
        XFree(screens);
1319
1314
    }
1320
1315
    else