~ubuntu-branches/ubuntu/trusty/sblim-sfcb/trusty-proposed

« back to all changes in this revision

Viewing changes to httpAdapter.c

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2009-06-08 12:04:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090608120449-byfplk09rqz8rtg6
Tags: 1.3.3-0ubuntu1
* New upstream release.
* debian/rules: Removed rpath hacks, SFCB default build handles that now.
* Removed 1934753-remove-assignment.diff, now upstream.
* Refreshed patch cim-schema-location.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
#include <sys/ipc.h>
55
55
#include <sys/sem.h>
56
56
 
 
57
#ifdef HAVE_SYS_FSUID_H
 
58
#include <sys/fsuid.h>
 
59
#endif
 
60
 
57
61
#include "httpComm.h"
58
62
#include "sfcVersion.h"
59
63
#include "control.h"
60
64
 
 
65
#ifdef HAVE_UDS
 
66
#include <grp.h>
 
67
#include <sys/stat.h>
 
68
#endif
 
69
 
61
70
unsigned long exFlags = 0;
62
71
static char *name;
63
72
static int debug;
64
73
static int doBa;
 
74
#ifdef HAVE_UDS
 
75
static int doUdsAuth;
 
76
#endif
65
77
static int doFork = 0;
66
78
int noChunking = 0;
67
79
int sfcbSSLMode = 0;
74
86
static long keepaliveTimeout=15;
75
87
static long keepaliveMaxRequest=10;
76
88
static long numRequest;
 
89
struct timeval httpSelectTimeout = {5, 0};  /* 5 sec. timeout for select() before read() */
77
90
 
78
91
#if defined USE_SSL
79
92
static SSL_CTX *ctx;
92
105
static int httpWorkSem;
93
106
 
94
107
extern char *decode64(char *data);
95
 
extern void libraryName(const char* dir, const char *location, char *fullName);
 
108
extern void libraryName(const char* dir, const char *location, char *fullName, int buf_size);
96
109
extern void *loadLibib(const char *libname);
97
110
extern int getControlChars(char *id, char **val);
98
111
extern void *loadLibib(const char *libname);
203
216
 
204
217
   if (err==0 && authLib==NULL) {
205
218
      char *ln;
206
 
      int err=1;
 
219
      err=1;
207
220
      if (getControlChars("basicAuthlib", &ln)==0) {
208
 
         libraryName(NULL,ln,dlName);
 
221
         libraryName(NULL,ln,dlName, 512);
209
222
        if ((authLib=dlopen(dlName, RTLD_LAZY))) {
210
223
            authenticate= dlsym(authLib, "_sfcBasicAuthenticate");
211
224
            if (authenticate) err=0;
214
227
      if (err) mlogf(M_ERROR,M_SHOW,"--- Authentication exit %s not found\n",dlName);
215
228
   }
216
229
 
217
 
   *principal=strdup(auth);
218
 
   if (authenticate(auth,pw)) 
219
 
                ret = 1;
 
230
   if (err) {
 
231
     ret = 1;
 
232
   } 
 
233
   else {
 
234
     *principal=strdup(auth);
 
235
     if (authenticate(auth,pw)) 
 
236
       ret = 1;
 
237
   }
220
238
 
221
239
   free(auth);
222
240
 
251
269
   errno = oerrno;
252
270
}
253
271
 
 
272
static void stopProc(void *p)
 
273
{
 
274
//   printf("--- %s draining %d\n",processName,running);
 
275
   for (;;) {
 
276
      if (running==0) {
 
277
         mlogf(M_INFO,M_SHOW,"--- %s terminating %d\n",processName,getpid());
 
278
         exit(0);
 
279
      }   
 
280
      sleep(1);
 
281
   }   
 
282
}
 
283
 
254
284
static void handleSigUsr1(int sig)
255
285
{
256
 
   stopAccepting=1;
 
286
   pthread_t t;
 
287
   pthread_attr_t tattr;
 
288
 
 
289
   if (stopAccepting == 0) {
 
290
     stopAccepting=1;
 
291
     pthread_attr_init(&tattr);
 
292
     pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);      
 
293
     pthread_create(&t, &tattr, (void *(*)(void *))stopProc,NULL);
 
294
   }
257
295
}
258
296
 
259
297
static void freeBuffer(Buffer * b)
260
298
{
261
 
   Buffer emptyBuf = { NULL, NULL, 0, 0, 0, 0, 0 ,0};
 
299
   Buffer emptyBuf = { NULL, NULL, 0, 0, 0, 0, 0 , NULL, NULL, NULL, NULL, NULL, NULL, NULL};
262
300
   if (b->data)
263
301
      free(b->data);
264
302
   if (b->content)
265
303
      free(b->content);
 
304
   if (b->principal)
 
305
      free(b->principal);
266
306
   *b=emptyBuf;   
267
307
}
268
308
 
333
373
 
334
374
static int readData(CommHndl conn_fd, char *into, int length)
335
375
{
336
 
   int c = 0, r;
 
376
   int c = 0, r, isReady;
 
377
   fd_set httpfds;
 
378
   FD_ZERO(&httpfds);
 
379
   FD_SET(conn_fd.socket,&httpfds);
337
380
 
338
381
   while (c < length) {
 
382
      isReady = select(conn_fd.socket+1,&httpfds,NULL,NULL,&httpSelectTimeout);
 
383
      if (isReady == 0) {
 
384
         c = -1;
 
385
         break;
 
386
      }
339
387
      r = commRead(conn_fd, into + c, length - c);
340
388
      if (r < 0 && (errno == EINTR || errno == EAGAIN)) {
341
389
         continue;
342
390
      }
 
391
      /* r==0 is a success condition for read(), but the loop should complete prior to this */
 
392
      else if (r == 0) {
 
393
         mlogf(M_INFO,M_SHOW,"--- commRead hit EOF sooner than expected\n");
 
394
         c = -2;
 
395
         break;
 
396
      }
343
397
      c += r;
344
398
   }
345
399
   return c;
346
400
}
347
401
 
348
 
static void getPayload(CommHndl conn_fd, Buffer * b)
 
402
static int getPayload(CommHndl conn_fd, Buffer * b)
349
403
{
350
404
   int c = b->length - b->ptr;
 
405
   int rc = 0;
351
406
   b->content = (char *) malloc(b->content_length + 8);
352
407
   if (c) memcpy(b->content, (b->data) + b->ptr, c);
353
408
 
354
 
   readData(conn_fd, (b->content) + c, b->content_length - c);
 
409
   if (c > b->content_length) {
 
410
     mlogf(M_INFO,M_SHOW,"--- HTTP Content-Length is lying; content truncated\n");
 
411
     c = b->content_length;
 
412
   }
 
413
 
 
414
   rc = readData(conn_fd, (b->content) + c, b->content_length - c);
355
415
   *((b->content) + b->content_length) = 0;
 
416
   return rc;
356
417
}
357
418
 
358
419
void dumpResponse(RespSegments * rs)
571
632
#define hdrBufsize 5000
572
633
#define hdrLimmit 5000
573
634
 
574
 
static int  getHdrs(CommHndl conn_fd, Buffer * b, char *cmd)
 
635
static int getHdrs(CommHndl conn_fd, Buffer * b, char *cmd)
575
636
{
576
637
   int first=1,total=0,isReady;
577
 
   struct timeval httpTimeout;
578
638
   fd_set httpfds;
579
639
   int state=0;
580
640
   
581
641
   FD_ZERO(&httpfds);
582
642
   FD_SET(conn_fd.socket,&httpfds);
583
 
   httpTimeout.tv_sec=5;
584
 
   httpTimeout.tv_usec=0;
585
 
   isReady = select(conn_fd.socket+1,&httpfds,NULL,NULL,&httpTimeout);
586
 
   if (isReady == 0) return 3;
587
643
        
588
644
   for (;;) {
 
645
      isReady = select(conn_fd.socket+1,&httpfds,NULL,NULL,&httpSelectTimeout);
 
646
      if (isReady == 0) return 3;
 
647
 
589
648
      char buf[hdrBufsize];
590
649
      int r = commRead(conn_fd, buf, sizeof(buf));
591
650
      
592
651
      if (r < 0 && (errno == EINTR || errno == EAGAIN)) continue;
593
 
      if (r <= 0) break;
 
652
      if (r == 0) {
 
653
        if (b->size == 0) break;
 
654
        if (strstr(b->data, "\r\n\r\n") == NULL &&
 
655
            strstr(b->data, "\n\n") == NULL) {
 
656
                mlogf(M_ERROR,M_SHOW,"-#- HTTP header ended prematurely\n");
 
657
            state = 3;
 
658
                break; 
 
659
            }
 
660
      }
594
661
      
595
662
      add2buffer(b, buf, r);
596
663
      total+=r;
597
 
//      fprintf(stderr,"+++ buf: >%s<\n",buf);
 
664
 
 
665
      /* on first run through, ensure that this is a POST req. */
598
666
      if (r && first) {
599
667
         if (strncasecmp(buf,cmd,strlen(cmd)) != 0) { 
600
668
           /* not what we expected - still continue to read to
603
671
         }
604
672
         first=0;
605
673
      }
606
 
      
 
674
 
 
675
      /* success condition: end of header */
607
676
      if (strstr(b->data, "\r\n\r\n") != NULL ||
608
677
          strstr(b->data, "\n\n") != NULL) {
609
678
         break;
677
746
   int badReq = 0;
678
747
 
679
748
   rc=getHdrs(conn_fd, &inBuf,"POST ");
680
 
   
 
749
 
681
750
   if (rc==1) { 
682
751
      genError(conn_fd, &inBuf, 501, "Not Implemented", NULL);
683
752
      /* we continue to parse headers and empty the socket
744
813
         cp = &hdr[15];
745
814
         cp += strspn(cp, " \t");
746
815
         inBuf.content_length = atol(cp);
 
816
         long maxLen;
 
817
         getControlNum("httpMaxContentLength", &maxLen);
 
818
         if((maxLen) && (inBuf.content_length > maxLen)) {
 
819
            genError(conn_fd, &inBuf, 413, "Request Entity Too Large", NULL);
 
820
            _SFCB_TRACE(1, ("--- exiting: content-length too big"));      
 
821
            commClose(conn_fd);
 
822
            exit(1);
 
823
         }
747
824
      }
748
825
      else if (strncasecmp(hdr, "Content-Type:", 13) == 0) {
749
826
         cp = &hdr[13];
800
877
   }
801
878
#endif
802
879
 
803
 
   if (!discardInput && doBa) {
 
880
   int authorized = 0; 
 
881
#ifdef HAVE_UDS
 
882
   if (!discardInput && doUdsAuth) {
 
883
       struct sockaddr_un sun; 
 
884
       sun.sun_family = 0; 
 
885
       socklen_t cl = sizeof(sun); 
 
886
       int rc = getpeername(conn_fd.socket, (struct sockaddr*)&sun, &cl); 
 
887
       if (rc == 0 && sun.sun_family == AF_UNIX) {
 
888
           /* Already authenticated via permissions on unix socket */
 
889
           authorized = 1;
 
890
       }
 
891
   }
 
892
#endif
 
893
   if (!authorized && !discardInput && doBa) {
804
894
     if (!(inBuf.authorization && baValidate(inBuf.authorization,&inBuf.principal))) {
805
895
       char more[]="WWW-Authenticate: Basic realm=\"cimom\"\r\n";
806
896
       genError(conn_fd, &inBuf, 401, "Unauthorized", more);
823
913
     }
824
914
     _SFCB_TRACE(1, ("--- exiting after missing content length."));      
825
915
     commClose(conn_fd);
 
916
     freeBuffer(&inBuf);
826
917
     exit(1);
827
918
   }
828
919
 
830
921
   len += hl =
831
922
       sprintf(hdr, "<!-- xml -->\n<!-- auth: %s -->\n", inBuf.authorization);
832
923
 
833
 
   getPayload(conn_fd, &inBuf);
 
924
   rc = getPayload(conn_fd, &inBuf);
 
925
   if (rc < 0) {
 
926
      genError(conn_fd, &inBuf, 400, "Bad Request", NULL);
 
927
      _SFCB_TRACE(1, ("--- exiting after request timeout."));
 
928
      commClose(conn_fd);
 
929
      exit(1);
 
930
   }
834
931
   if (discardInput) {
835
932
     free(hdr);
836
933
     freeBuffer(&inBuf);
1272
1369
            /* still in handshake */
1273
1370
            FD_ZERO(&httpfds);
1274
1371
            FD_SET(connFd,&httpfds);
1275
 
            httpTimeout.tv_sec=5;
1276
 
            httpTimeout.tv_usec=0;
1277
1372
            if (sslerr == SSL_ERROR_WANT_WRITE) {
1278
 
              isReady = select(connFd+1,NULL,&httpfds,NULL,&httpTimeout);
 
1373
              isReady = select(connFd+1,NULL,&httpfds,NULL,&httpSelectTimeout);
1279
1374
            } else {
1280
 
              isReady = select(connFd+1,&httpfds,NULL,NULL,&httpTimeout);
 
1375
              isReady = select(connFd+1,&httpfds,NULL,NULL,&httpSelectTimeout);
1281
1376
            }
1282
1377
            if (isReady == 0) {
1283
1378
              intSSLerror("Timeout error accepting SSL connection");
1355
1450
#else
1356
1451
   struct sockaddr_in sin;
1357
1452
#endif
 
1453
   struct sockaddr_un sun; 
1358
1454
 
1359
 
   socklen_t sz,sin_len;
1360
 
   int i,ru;
 
1455
   socklen_t sz,sin_len,sun_len;
 
1456
   int i,ru,rc;
1361
1457
   char *cp;
1362
1458
   long procs, port;
1363
 
   int listenFd, connFd;
 
1459
   int listenFd=-1, connFd; 
 
1460
   int enableHttp=0;
 
1461
   fd_set httpfds;
 
1462
   int maxfdp1; 
 
1463
 
 
1464
#ifdef HAVE_UDS
 
1465
   static char *udsPath=NULL;
 
1466
   int enableUds=0;
 
1467
   int  udsListenFd=-1;
 
1468
#endif
1364
1469
 
1365
1470
   name = argv[0];
1366
1471
   debug = 1;
1382
1487
   else {
1383
1488
      if (getControlNum("httpPort", &port))
1384
1489
         port = 5988;
 
1490
#ifdef HAVE_UDS
 
1491
      if (getControlChars("httpSocketPath", &udsPath)) 
 
1492
                 udsPath = "/tmp/sfcbHttpSocket"; 
 
1493
#endif
1385
1494
      hBase=htBase;
1386
1495
      hMax=htMax;
1387
1496
   }
1392
1501
   } else {
1393
1502
     if (getControlNum("httpProcs", &procs))
1394
1503
       procs = 10;
 
1504
     if (getControlBool("enableHttp", &enableHttp))
 
1505
       enableHttp=1;
 
1506
#ifdef HAVE_UDS
 
1507
         if (getControlBool("enableUds", &enableUds))
 
1508
       enableUds=1;
 
1509
         if (!enableUds)
 
1510
                 udsPath = NULL; 
 
1511
#endif
 
1512
         if (!enableHttp)
 
1513
                 port = -1; 
1395
1514
   }
1396
1515
   initHttpProcCtl(procs,sslMode);
1397
1516
 
1398
1517
   if (getControlBool("doBasicAuth", &doBa))
1399
1518
      doBa=0;
1400
1519
 
 
1520
#ifdef HAVE_UDS
 
1521
   if (getControlBool("doUdsAuth", &doUdsAuth))
 
1522
      doUdsAuth=0;
 
1523
#endif
 
1524
 
1401
1525
   if (getControlNum("keepaliveTimeout", &keepaliveTimeout))
1402
1526
     keepaliveTimeout = 15;
1403
1527
 
1439
1563
 
1440
1564
   if (sslMode) mlogf(M_INFO,M_SHOW,"--- %s HTTPS Daemon V" sfcHttpDaemonVersion " started - %d - port %ld\n", 
1441
1565
         name, currentProc,port);
1442
 
   else mlogf(M_INFO,M_SHOW,"--- %s HTTP  Daemon V" sfcHttpDaemonVersion " started - %d - port %ld\n", 
1443
 
         name, currentProc,port);
1444
 
 
 
1566
#ifdef HAVE_UDS
 
1567
   else mlogf(M_INFO,M_SHOW,"--- %s HTTP  Daemon V" sfcHttpDaemonVersion " started - %d - port %ld, %s\n", 
 
1568
         name, currentProc,port,udsPath);
 
1569
#endif
1445
1570
 
1446
1571
   if (doBa) mlogf(M_INFO,M_SHOW,"--- Using Basic Authentication\n");
 
1572
#ifdef HAVE_UDS
 
1573
   if (doUdsAuth) mlogf(M_INFO,M_SHOW,"--- Using Unix Socket Peer Cred Authentication\n");
 
1574
#endif
1447
1575
 
1448
1576
   if (keepaliveTimeout == 0) {
1449
1577
     mlogf(M_INFO,M_SHOW,"--- Keep-alive timeout disabled\n");
1452
1580
     mlogf(M_INFO,M_SHOW,"--- Maximum requests per connection: %ld\n",keepaliveMaxRequest);
1453
1581
   }
1454
1582
 
 
1583
   ru = 1;
 
1584
#ifdef HAVE_UDS
 
1585
   if (enableUds) {
 
1586
      udsListenFd = socket(PF_UNIX, SOCK_STREAM, 0); 
 
1587
   }
 
1588
#endif
 
1589
   if (enableHttp || sslMode) {
1455
1590
#ifdef USE_INET6
1456
 
   listenFd = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
1457
 
   if (listenFd < 0) { 
1458
 
       mlogf(M_INFO,M_SHOW,"--- Using IPv4 address\n");
1459
 
       listenFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
1460
 
   }
 
1591
      listenFd = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
 
1592
      if (listenFd < 0) { 
 
1593
          mlogf(M_INFO,M_SHOW,"--- Using IPv4 address\n");
 
1594
          listenFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
1595
      }
1461
1596
#else
1462
 
   listenFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
1597
      listenFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
1463
1598
#endif
 
1599
      setsockopt(listenFd, SOL_SOCKET, SO_REUSEADDR, (char *) &ru, sizeof(ru));
 
1600
   }
1464
1601
 
1465
1602
   sin_len = sizeof(sin);
1466
 
 
1467
 
   ru = 1;
1468
 
   setsockopt(listenFd, SOL_SOCKET, SO_REUSEADDR, (char *) &ru, sizeof(ru));
 
1603
   sun_len = sizeof(sun); 
1469
1604
 
1470
1605
   memset(&sin,0,sin_len);
1471
 
 
1472
 
   if (getControlBool("httpLocalOnly", &httpLocalOnly))
1473
 
      httpLocalOnly=0;
 
1606
   memset(&sun,0,sun_len);
 
1607
 
 
1608
#ifdef HAVE_UDS
 
1609
   if (udsListenFd >= 0) {
 
1610
     if (getControlChars("httpSocketPath", &udsPath)) {
 
1611
         mlogf(M_ERROR,M_SHOW,"--- No unix socket path defined for HTTP\n"); 
 
1612
         sleep(1);
 
1613
         kill(sfcbPid,3);
 
1614
     }
 
1615
     sun.sun_family=AF_UNIX;
 
1616
     strcpy(sun.sun_path,udsPath);
 
1617
   }
 
1618
#endif
 
1619
 
 
1620
   if (listenFd >= 0) {
 
1621
      if (getControlBool("httpLocalOnly", &httpLocalOnly))
 
1622
            httpLocalOnly=0;
1474
1623
 
1475
1624
#ifdef USE_INET6
1476
 
   sin.sin6_family = AF_INET6;
1477
 
   if (httpLocalOnly)
1478
 
     sin.sin6_addr = in6addr_loopback;
1479
 
   else
1480
 
     sin.sin6_addr = in6addr_any;
1481
 
   sin.sin6_port = htons(port);
 
1625
     sin.sin6_family = AF_INET6;
 
1626
     if (httpLocalOnly)
 
1627
           sin.sin6_addr = in6addr_loopback;
 
1628
     else
 
1629
           sin.sin6_addr = in6addr_any;
 
1630
     sin.sin6_port = htons(port);
1482
1631
#else
1483
 
   sin.sin_family = AF_INET;
1484
 
   if (httpLocalOnly) {
1485
 
     char* loopback_int = "127.0.0.1";
1486
 
     inet_aton(loopback_int, &sin.sin_addr); /* not INADDR_LOOPBACK ? */
1487
 
   }
1488
 
   else
1489
 
     sin.sin_addr.s_addr = INADDR_ANY;
1490
 
   sin.sin_port = htons(port);
 
1632
     sin.sin_family = AF_INET;
 
1633
     if (httpLocalOnly) {
 
1634
           char* loopback_int = "127.0.0.1";
 
1635
           inet_aton(loopback_int, &sin.sin_addr); /* not INADDR_LOOPBACK ? */
 
1636
     }
 
1637
     else
 
1638
           sin.sin_addr.s_addr = INADDR_ANY;
 
1639
     sin.sin_port = htons(port);
1491
1640
#endif 
1492
 
 
1493
 
   if (bind(listenFd, (struct sockaddr *) &sin, sin_len) ||
1494
 
       listen(listenFd, 0)) {
1495
 
      mlogf(M_ERROR,M_SHOW,"--- Cannot listen on port %ld (%s)\n", port, strerror(errno));
1496
 
      sleep(1);
1497
 
      kill(sfcbPid,3);
1498
1641
   }
1499
1642
 
 
1643
  if (listenFd >= 0) {
 
1644
     if (bind(listenFd, (struct sockaddr *) &sin, sin_len) ||
 
1645
             listen(listenFd, 10)) {
 
1646
            mlogf(M_ERROR,M_SHOW,"--- Cannot listen on port %ld (%s)\n", port, strerror(errno));
 
1647
            sleep(1);
 
1648
            kill(sfcbPid,3);
 
1649
     }
 
1650
  }
 
1651
#ifdef HAVE_UDS
 
1652
  if (udsListenFd >= 0) {
 
1653
     unlink(udsPath); 
 
1654
 
 
1655
     size_t gbuflen = sysconf(_SC_GETGR_R_SIZE_MAX); 
 
1656
     char gbuf[gbuflen]; 
 
1657
     struct group* pgrp = NULL; 
 
1658
     struct group grp; 
 
1659
     gid_t oldfsgid = 0; 
 
1660
 
 
1661
     int rc = getgrnam_r("sfcb", &grp, gbuf, gbuflen, &pgrp); 
 
1662
     if (rc == 0 && pgrp)
 
1663
     {
 
1664
#ifdef HAVE_SYS_FSUID_H
 
1665
         oldfsgid = setfsgid(pgrp->gr_gid); 
 
1666
#else
 
1667
         oldfsgid = setegid(pgrp->gr_gid); 
 
1668
#endif
 
1669
     }
 
1670
     mode_t oldmask = umask(0007); 
 
1671
     if (bind(udsListenFd, (struct sockaddr *) &sun, sun_len) ||
 
1672
             listen(udsListenFd, 10)) {
 
1673
            mlogf(M_ERROR,M_SHOW,"--- Cannot listen on unix socket %s (%s)\n", udsPath, strerror(errno));
 
1674
            sleep(1);
 
1675
            kill(sfcbPid,3);
 
1676
     }
 
1677
     umask(oldmask); 
 
1678
     if (pgrp)
 
1679
     {
 
1680
#ifdef HAVE_SYS_FSUID_H
 
1681
         setfsgid(oldfsgid); 
 
1682
#else
 
1683
         setegid(oldfsgid); 
 
1684
#endif
 
1685
     }
 
1686
  }
 
1687
#endif
 
1688
 
1500
1689
  if (!debug) {
1501
1690
      int rc = fork();
1502
1691
      if (rc == -1) {
1554
1743
       if (ccVerifyMode != CC_VERIFY_IGNORE &&
1555
1744
           SSL_CTX_load_verify_locations(ctx, fnt, NULL) != 1)
1556
1745
         intSSLerror("Error locating the client trust store");
 
1746
 
 
1747
       /* SSLv2 is pretty old; no one should be needing it any more */
 
1748
       SSL_CTX_set_options(ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2 | 
 
1749
                           SSL_OP_SINGLE_DH_USE); 
 
1750
       /* disable weak ciphers */
 
1751
       if (SSL_CTX_set_cipher_list(ctx, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH") != 1)
 
1752
           intSSLerror("Error setting cipher list (no valid ciphers)"); 
1557
1753
              
1558
1754
    }
1559
1755
#endif
1560
1756
 
 
1757
#ifdef HAVE_UDS
 
1758
   maxfdp1 = (listenFd > udsListenFd? listenFd : udsListenFd) + 1; 
 
1759
#else
 
1760
   maxfdp1 = listenFd + 1; 
 
1761
#endif
1561
1762
   for (;;) {
1562
 
   char *emsg;
1563
 
      listen(listenFd, 1);
1564
 
      sz = sizeof(sin);
1565
 
      if ((connFd = accept(listenFd, (__SOCKADDR_ARG) & sin, &sz))<0) {
 
1763
      char *emsg;
 
1764
      // listen(listenFd, 1);
 
1765
          FD_ZERO(&httpfds); 
 
1766
          if (listenFd >= 0) {
 
1767
         FD_SET(listenFd, &httpfds); 
 
1768
          }
 
1769
#ifdef HAVE_UDS
 
1770
          if (udsListenFd >= 0) {
 
1771
         FD_SET(udsListenFd, &httpfds); 
 
1772
      }
 
1773
#endif
 
1774
          rc = select(maxfdp1, &httpfds, NULL, NULL, NULL); 
 
1775
          if (stopAccepting) break;
 
1776
      if (rc < 0) {
1566
1777
         if (errno == EINTR || errno == EAGAIN) {
1567
 
            if (stopAccepting) break;
1568
1778
            continue;
1569
 
         }   
1570
 
         emsg=strerror(errno);
1571
 
         mlogf(M_ERROR,M_SHOW,"--- accept error %s\n",emsg);
1572
 
         _SFCB_ABORT();
 
1779
         }
1573
1780
      }
1574
 
      _SFCB_TRACE(1, ("--- Processing http request"));
1575
 
 
1576
 
      handleHttpRequest(connFd);
1577
 
      close(connFd);
 
1781
          if (listenFd >= 0 && FD_ISSET(listenFd, &httpfds)) {
 
1782
                  sz = sin_len; 
 
1783
                  if ((connFd = accept(listenFd, (__SOCKADDR_ARG) &sin, &sz))<0) {
 
1784
                         if (errno == EINTR || errno == EAGAIN) {
 
1785
                                continue;
 
1786
                         }   
 
1787
                         emsg=strerror(errno);
 
1788
                         mlogf(M_ERROR,M_SHOW,"--- accept error %s\n",emsg);
 
1789
                         _SFCB_ABORT();
 
1790
                  }
 
1791
                  _SFCB_TRACE(1, ("--- Processing http request"));
 
1792
 
 
1793
                  handleHttpRequest(connFd);
 
1794
                  close(connFd);
 
1795
          }
 
1796
#ifdef HAVE_UDS
 
1797
          if (udsListenFd >= 0 && FD_ISSET(udsListenFd, &httpfds)) {
 
1798
                  sz = sun_len; 
 
1799
                  if ((connFd = accept(udsListenFd, (__SOCKADDR_ARG) &sun, &sz))<0) {
 
1800
                         if (errno == EINTR || errno == EAGAIN) {
 
1801
                                continue;
 
1802
                         }   
 
1803
                         emsg=strerror(errno);
 
1804
                         mlogf(M_ERROR,M_SHOW,"--- accept error %s\n",emsg);
 
1805
                         _SFCB_ABORT();
 
1806
                  }
 
1807
                  _SFCB_TRACE(1, ("--- Processing http request"));
 
1808
 
 
1809
                  handleHttpRequest(connFd);
 
1810
                  close(connFd);
 
1811
          }
 
1812
#endif
1578
1813
   }
1579
1814
   
1580
1815
   remProcCtl();   
1581
1816
   
1582
 
//   printf("--- %s draining %d\n",processName,running);
1583
 
   for (;;) {
1584
 
      if (running==0) {
1585
 
         mlogf(M_INFO,M_SHOW,"--- %s terminating %d\n",processName,getpid());
1586
 
         exit(0);
1587
 
      }   
1588
 
      sleep(1);
1589
 
   }   
1590
 
 
 
1817
   while (1) {
 
1818
     sleep(5);
 
1819
   }
1591
1820
}
1592
1821
 
1593
1822
#if defined USE_SSL
1611
1840
  _SFCB_ENTER(TRACE_HTTPDAEMON, "ccValidate");
1612
1841
  
1613
1842
  if (getControlChars("certificateAuthlib", &ln)==0) {
1614
 
    libraryName(NULL,ln,dlName);
 
1843
    libraryName(NULL,ln,dlName, 512);
1615
1844
    if ((authLib=dlopen(dlName, RTLD_LAZY))) {
1616
1845
      validate= dlsym(authLib, "_sfcCertificateAuthenticate");
1617
1846
      if (validate) {
1624
1853
    }
1625
1854
  } else {
1626
1855
    mlogf(M_ERROR,M_SHOW,
1627
 
          "--- Certificate authentication exit not configured\n",dlName);       
 
1856
          "--- Certificate authentication exit not configured\n");      
1628
1857
  }
1629
1858
  _SFCB_RETURN(result);
1630
1859
}