~ubuntu-branches/debian/squeeze/ntp/squeeze-201010051545

« back to all changes in this revision

Viewing changes to ntpd/ntpd.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2009-11-26 22:16:37 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20091126221637-lbtdp0ax1yg9t0bx
Tags: 1:4.2.4p7+dfsg-4
* Use uname -s instead of dpkg-architecture to found the kernel we're
  running on.  dpkg-architecture is part of dpkg-dev. (Closes: #558145)
* Make the package fail to build on hurd since it does not provided
  the needed system calls for ntpd to work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
# include <sys/stat.h>
27
27
#endif
28
28
#include <stdio.h>
29
 
#ifndef SYS_WINNT
30
 
# if !defined(VMS)      /*wjm*/
31
 
#  ifdef HAVE_SYS_PARAM_H
32
 
#   include <sys/param.h>
33
 
#  endif
34
 
# endif /* VMS */
35
 
# ifdef HAVE_SYS_SIGNAL_H
36
 
#  include <sys/signal.h>
37
 
# else
38
 
#  include <signal.h>
 
29
#if !defined(VMS)       /*wjm*/
 
30
# ifdef HAVE_SYS_PARAM_H
 
31
#  include <sys/param.h>
39
32
# endif
40
 
# ifdef HAVE_SYS_IOCTL_H
41
 
#  include <sys/ioctl.h>
42
 
# endif /* HAVE_SYS_IOCTL_H */
43
 
# ifdef HAVE_SYS_RESOURCE_H
44
 
#  include <sys/resource.h>
45
 
# endif /* HAVE_SYS_RESOURCE_H */
 
33
#endif /* VMS */
 
34
#ifdef HAVE_SYS_SIGNAL_H
 
35
# include <sys/signal.h>
46
36
#else
47
37
# include <signal.h>
48
 
# include <process.h>
49
 
# include <io.h>
50
 
# include <clockstuff.h>
51
 
#include "ntp_iocompletionport.h"
52
 
#endif /* SYS_WINNT */
 
38
#endif
 
39
#ifdef HAVE_SYS_IOCTL_H
 
40
# include <sys/ioctl.h>
 
41
#endif /* HAVE_SYS_IOCTL_H */
 
42
#ifdef HAVE_SYS_RESOURCE_H
 
43
# include <sys/resource.h>
 
44
#endif /* HAVE_SYS_RESOURCE_H */
53
45
#if defined(HAVE_RTPRIO)
54
46
# ifdef HAVE_SYS_RESOURCE_H
55
47
#  include <sys/resource.h>
168
160
char *user = NULL;              /* User to switch to */
169
161
char *group = NULL;             /* group to switch to */
170
162
char *chrootdir = NULL;         /* directory to chroot to */
 
163
int have_caps = 0;              /* runtime check whether capabilities work,
 
164
                                   leave at 0 here */
171
165
int sw_uid;
172
166
int sw_gid;
173
167
char *endp;  
506
500
        }
507
501
#endif
508
502
 
509
 
#ifdef OPENSSL
510
 
        if ((SSLeay() ^ OPENSSL_VERSION_NUMBER) & ~0xff0L) {
511
 
                msyslog(LOG_ERR,
512
 
                    "ntpd: OpenSSL version mismatch. Built against %lx, you have %lx\n",
513
 
                    OPENSSL_VERSION_NUMBER, SSLeay());
514
 
                exit(1);
515
 
        }
516
 
#endif
517
 
 
518
503
        /* getstartup(argc, argv); / * startup configuration, may set debug */
519
504
 
520
505
#ifdef DEBUG
821
806
        init_restrict();
822
807
        init_mon();
823
808
        init_timer();
824
 
#if defined (HAVE_IO_COMPLETION_PORT)
825
 
        init_io_completion_port();
826
 
#endif
827
809
        init_lib();
828
810
        init_request();
829
811
        init_control();
851
833
#endif /* OPENSSL */
852
834
        initializing = 0;
853
835
 
 
836
#ifdef HAVE_LINUX_CAPABILITIES
 
837
        {
 
838
                /*  Check that setting capabilities actually works; we might be
 
839
                 *  run on a kernel with disabled capabilities. We must not
 
840
                 *  drop privileges in this case.
 
841
                 */
 
842
                cap_t caps;
 
843
                if( ! ( caps = cap_from_text( "cap_sys_time,cap_setuid,cap_setgid,cap_sys_chroot,cap_net_bind_service=pe" ) ) ) {
 
844
                        msyslog( LOG_ERR, "cap_from_text() failed: %m" );
 
845
                        exit(-1);
 
846
                }
 
847
                if( cap_set_proc( caps ) == 0 )
 
848
                    have_caps = 1;
 
849
                cap_free( caps );
 
850
        }
 
851
#endif /* HAVE_LINUX_CAPABILITIES */
 
852
 
854
853
#ifdef HAVE_DROPROOT
 
854
#ifdef HAVE_LINUX_CAPABILITIES
 
855
        if( droproot && have_caps ) {
 
856
#else
855
857
        if( droproot ) {
 
858
#endif
856
859
                /* Drop super-user privileges and chroot now if the OS supports this */
857
860
 
858
861
#ifdef HAVE_LINUX_CAPABILITIES
879
882
                                if ((pw = getpwnam(user)) != NULL) {
880
883
                                        sw_uid = pw->pw_uid;
881
884
                                } else {
882
 
                                        errno = 0;
883
885
                                        msyslog(LOG_ERR, "Cannot find user `%s'", user);
884
886
                                        exit (-1);
885
887
                                }
953
955
                         */
954
956
                        cap_t caps;
955
957
                        char *captext = interface_interval ?
956
 
                                "cap_sys_time,cap_net_bind_service=ipe" :
957
 
                                "cap_sys_time=ipe";
 
958
                                "cap_sys_time,cap_net_bind_service=pe" :
 
959
                                "cap_sys_time=pe";
958
960
                        if( ! ( caps = cap_from_text( captext ) ) ) {
959
961
                                msyslog( LOG_ERR, "cap_from_text() failed: %m" );
960
962
                                exit(-1);
993
995
#if defined(HAVE_IO_COMPLETION_PORT)
994
996
 
995
997
        for (;;) {
996
 
                int tot_full_recvbufs = GetReceivedBuffers();
 
998
                GetReceivedBuffers();
997
999
#else /* normal I/O */
998
1000
 
999
1001
        BLOCK_IO_AND_ALARM();