source: branches/samba-3.5.x/source4/ntp_signd/ntp-dev-4.2.5p125.diff

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 16.3 KB
  • include/ntp_config.h

    Only in ntp-samba: autom4te.cache
    Only in ntp-samba: config.h
    Only in ntp-samba: config.log
    Only in ntp-samba: config.status
    Only in ntp-samba/ElectricFence: .deps
    Only in ntp-samba/ElectricFence: Makefile
    Only in ntp-samba: .gcc-warning
    Only in ntp-samba/include/isc: Makefile
    Only in ntp-samba/include: Makefile
    diff -ur ntp-dev-4.2.5p125/include/ntp_config.h ntp-samba/include/ntp_config.h
    old new  
    9292    int requested_key;
    9393    int revoke;
    9494    queue *trusted_key_list;
     95    char *ntp_signd_socket;
    9596};
    9697
    9798struct filegen_node {
  • include/ntpd.h

    diff -ur ntp-dev-4.2.5p125/include/ntpd.h ntp-samba/include/ntpd.h
    old new  
    259259extern int      config_priority;
    260260#endif
    261261
     262extern char const *ntp_signd_socket;
     263
    262264/* ntp_control.c */
    263265extern int      num_ctl_traps;
    264266extern keyid_t  ctl_auth_keyid;         /* keyid used for authenticating write requests */
     
    471473extern struct refclock *refclock_conf[]; /* refclock configuration table */
    472474extern u_char   num_refclock_conf;
    473475#endif
     476
     477/* ntp_signd.c */
     478#ifdef HAVE_NTP_SIGND
     479extern void
     480send_via_ntp_signd(
     481        struct recvbuf *rbufp,  /* receive packet pointer */
     482        int     xmode,
     483        keyid_t xkeyid,
     484        int flags,
     485        struct pkt  *xpkt
     486        );
     487#endif
  • include/ntp.h

    diff -ur ntp-dev-4.2.5p125/include/ntp.h ntp-samba/include/ntp.h
    old new  
    447447#ifdef  OPENSSL
    448448#define FLAG_ASSOC      0x4000  /* autokey request */
    449449#endif /* OPENSSL */
     450#define FLAG_ADKEY      0x00010000      /* Authenticated (or wants reply to be authenticated) using AD authentication */
    450451
    451452/*
    452453 * Definitions for the clear() routine.  We use memset() to clear
  • ntpd/Makefile.am

    Only in ntp-samba/include: ntp.h.orig
    Only in ntp-samba: libtool
    Only in ntp-samba: Makefile
    diff -ur ntp-dev-4.2.5p125/ntpd/Makefile.am ntp-samba/ntpd/Makefile.am
    old new  
    6565        ntp_crypto.c ntp_filegen.c \
    6666        ntp_intres.c ntp_loopfilter.c ntp_monitor.c ntp_peer.c \
    6767        ntp_proto.c ntp_refclock.c ntp_request.c \
    68         ntp_restrict.c ntp_timer.c ntp_util.c \
     68        ntp_restrict.c ntp_timer.c ntp_util.c ntp_signd.c \
    6969        ppsapi_timepps.h \
    7070        refclock_acts.c refclock_arbiter.c refclock_arc.c refclock_as2201.c \
    7171        refclock_atom.c refclock_bancomm.c refclock_chronolog.c \
  • ntpd/ntp_config.c

    diff -ur ntp-dev-4.2.5p125/ntpd/ntp_config.c ntp-samba/ntpd/ntp_config.c
    old new  
    148148#endif
    149149
    150150const char *config_file;
     151const char *ntp_signd_socket;
    151152#ifdef HAVE_NETINFO
    152153struct netinfo_config_state *config_netinfo = NULL;
    153154int check_netinfo = 1;
     
    276277        my_config.auth.crypto_cmd_list = NULL;
    277278        my_config.auth.keys = NULL;
    278279        my_config.auth.keysdir = NULL;
     280#ifdef NTP_SIGND_PATH
     281        my_config.auth.ntp_signd_socket = NTP_SIGND_PATH;
     282#else
     283        my_config.auth.ntp_signd_socket = NULL;
     284#endif
    279285        my_config.auth.requested_key = 0;
    280286        my_config.auth.revoke = 0;
    281287        my_config.auth.trusted_key_list = NULL;
     
    795801        { "crypto",             T_Crypto,          NO_ARG },
    796802        { "keys",               T_Keys,            SINGLE_ARG },
    797803        { "keysdir",            T_Keysdir,         SINGLE_ARG },
     804        { "ntpsigndsocket",     T_NtpSignDsocket,  SINGLE_ARG },
    798805        { "requestkey",         T_Requestkey,      NO_ARG },
    799806        { "revoke",             T_Revoke,          NO_ARG },
    800807        { "trustedkey",         T_Trustedkey,      NO_ARG },
     
    10001007        if (my_config.auth.keysdir)
    10011008                keysdir = my_config.auth.keysdir;
    10021009
     1010        /* ntp_signd_socket Command */
     1011        if (my_config.auth.ntp_signd_socket)
     1012                ntp_signd_socket = my_config.auth.ntp_signd_socket;
     1013
    10031014#ifdef OPENSSL
    10041015        if (cryptosw) {
    10051016                crypto_setup();
  • ntpd/ntp_parser.y

    Only in ntp-samba/ntpd: ntp_config.c~
    Only in ntp-samba/ntpd: ntp_config.c.orig
    diff -ur ntp-dev-4.2.5p125/ntpd/ntp_parser.y ntp-samba/ntpd/ntp_parser.y
    old new  
    155155%token          T_Novolley
    156156%token          T_Ntp
    157157%token          T_Ntpport
     158%token          T_NtpSignDsocket
    158159%token          T_Orphan
    159160%token          T_Panic
    160161%token          T_Peer
     
    432433                    { my_config.auth.requested_key = $2;  }
    433434        |       T_Trustedkey integer_list
    434435                    { my_config.auth.trusted_key_list = $2;  }
     436        |       T_NtpSignDsocket T_String
     437                    { my_config.auth.ntp_signd_socket = $2;  }
    435438        ;
    436439
    437440crypto_command_line
  • ntpd/ntp_proto.c

    diff -ur ntp-dev-4.2.5p125/ntpd/ntp_proto.c ntp-samba/ntpd/ntp_proto.c
    old new  
    128128static  void    clock_combine   (struct peer **, int);
    129129static  void    peer_xmit       (struct peer *);
    130130static  void    fast_xmit       (struct recvbuf *, int, keyid_t,
    131                                     char *);
     131                                 char *, int);
    132132static  void    clock_update    (struct peer *);
    133133static  int     default_get_precision (void);
    134134static  int     peer_unfit      (struct peer *);
     
    311311        int     authlen;                /* offset of MAC field */
    312312        int     is_authentic = 0;       /* cryptosum ok */
    313313        int     retcode = AM_NOMATCH;   /* match code */
     314        int     flags = 0;              /* flags with details about the authentication */
    314315        keyid_t skeyid = 0;             /* key IDs */
    315316        u_int32 opcode = 0;             /* extension field opcode */
    316317        struct sockaddr_storage *dstadr_sin; /* active runway */
     
    324325        keyid_t pkeyid = 0, tkeyid = 0; /* key IDs */
    325326#endif /* OPENSSL */
    326327
     328        static unsigned char zero_key[16];
     329
    327330        /*
    328331         * Monitor the packet and get restrictions. Note that the packet
    329332         * length for control and private mode packets must be checked
     
    480483                        return;                 /* rate exceeded */
    481484
    482485                if (hismode == MODE_CLIENT)
    483                         fast_xmit(rbufp, MODE_SERVER, skeyid, "RATE");
     486                        fast_xmit(rbufp, MODE_SERVER, skeyid, "RATE", 0);
    484487                else
    485                         fast_xmit(rbufp, MODE_ACTIVE, skeyid, "RATE");
     488                        fast_xmit(rbufp, MODE_ACTIVE, skeyid, "RATE", 0);
    486489                return;                         /* rate exceeded */
    487490        }
    488491
     
    535538         * is zero, acceptable outcomes of y are NONE and OK. If x is
    536539         * one, the only acceptable outcome of y is OK.
    537540         */
     541
    538542        if (has_mac == 0) {
    539543                is_authentic = AUTH_NONE; /* not required */
    540544#ifdef DEBUG
     
    555559                            stoa(&rbufp->recv_srcadr), hismode, skeyid,
    556560                            authlen + has_mac, is_authentic);
    557561#endif
     562
     563                /* If the signature is 20 bytes long, the last 16 of
     564                 * which are zero, then this is a Microsoft client
     565                 * wanting AD-style authentication of the server's
     566                 * reply. 
     567                 *
     568                 * This is described in Microsoft's WSPP docs, in MS-SNTP:
     569                 * http://msdn.microsoft.com/en-us/library/cc212930.aspx
     570                 */
     571        } else if (has_mac == MAX_MAC_LEN
     572                   && (retcode == AM_FXMIT || retcode == AM_NEWPASS)
     573                   && (memcmp(zero_key, (char *)pkt + authlen + 4, MAX_MAC_LEN - 4) == 0)) {
     574               
     575                /* Don't try to verify the zeros, just set a
     576                 * flag and otherwise pretend we never saw the signature */
     577                is_authentic = AUTH_NONE;
     578               
     579                flags = FLAG_ADKEY;
     580
    558581        } else {
    559582#ifdef OPENSSL
    560583                /*
     
    696719                        if (AUTH(restrict_mask & RES_DONTTRUST,
    697720                           is_authentic)) {
    698721                                fast_xmit(rbufp, MODE_SERVER, skeyid,
    699                                     NULL);
     722                                          NULL, flags);
    700723                        } else if (is_authentic == AUTH_ERROR) {
    701                                 fast_xmit(rbufp, MODE_SERVER, 0, NULL);
     724                                fast_xmit(rbufp, MODE_SERVER, 0, NULL, 0);
    702725                                sys_badauth++;
    703726                        } else {
    704727                                sys_restricted++;
     
    733756                 * crypto-NAK, as that would not be useful.
    734757                 */
    735758                if (AUTH(restrict_mask & RES_DONTTRUST, is_authentic))
    736                         fast_xmit(rbufp, MODE_SERVER, skeyid, NULL);
     759                        fast_xmit(rbufp, MODE_SERVER, skeyid, NULL, 0);
    737760                return;                         /* hooray */
    738761
    739762        /*
     
    888911                    is_authentic)) {
    889912#ifdef OPENSSL
    890913                        if (crypto_flags && skeyid > NTP_MAXKEY)
    891                                 fast_xmit(rbufp, MODE_ACTIVE, 0, NULL);
     914                                fast_xmit(rbufp, MODE_ACTIVE, 0, NULL, 0);
    892915#endif /* OPENSSL */
    893916                        sys_restricted++;
    894917                        return;                 /* access denied */
     
    904927                         * This is for drat broken Windows clients. See
    905928                         * Microsoft KB 875424 for preferred workaround.
    906929                         */
    907                         fast_xmit(rbufp, MODE_PASSIVE, skeyid, NULL);
     930                        fast_xmit(rbufp, MODE_PASSIVE, skeyid, NULL, flags);
    908931#else /* WINTIME */
    909932                        sys_restricted++;
    910933#endif /* WINTIME */
     
    938961                }
    939962                break;
    940963
     964
    941965        /*
    942966         * Process regular packet. Nothing special.
    943967         */
     
    10901114                peer->flash |= TEST5;           /* bad auth */
    10911115                peer->badauth++;
    10921116                if (hismode == MODE_ACTIVE || hismode == MODE_PASSIVE)
    1093                         fast_xmit(rbufp, MODE_ACTIVE, 0, NULL);
     1117                        fast_xmit(rbufp, MODE_ACTIVE, 0, NULL, 0);
    10941118                if (peer->flags & FLAG_PREEMPT) {
    10951119                        unpeer(peer);
    10961120                        return;
     
    31593183        struct recvbuf *rbufp,  /* receive packet pointer */
    31603184        int     xmode,          /* receive mode */
    31613185        keyid_t xkeyid,         /* transmit key ID */
    3162         char    *mask           /* kiss code */
     3186        char    *mask,          /* kiss code */
     3187        int     flags           /* Flags to indicate signing behaviour */
    31633188        )
    31643189{
    31653190        struct pkt xpkt;        /* transmit packet structure */
     
    32203245                HTONL_FP(&rbufp->recv_time, &xpkt.rec);
    32213246        }
    32223247
     3248        if (flags & FLAG_ADKEY) {
     3249#ifdef HAVE_NTP_SIGND
     3250                get_systime(&xmt_tx);
     3251                if (mask == NULL) {
     3252                        HTONL_FP(&xmt_tx, &xpkt.xmt);
     3253                }
     3254                send_via_ntp_signd(rbufp, xmode, xkeyid, flags, &xpkt);
     3255#endif
     3256                /* If we don't have the support, drop the packet on the floor. 
     3257                   An all zero sig is compleatly bogus anyway */
     3258                return;
     3259        }
     3260
    32233261        /*
    32243262         * If the received packet contains a MAC, the transmitted packet
    32253263         * is authenticated and contains a MAC. If not, the transmitted
     
    32523290         * source-destination-key ID combination.
    32533291         */
    32543292#ifdef OPENSSL
    3255         if (xkeyid > NTP_MAXKEY) {
     3293        if (!(flags & FLAG_ADKEY) && (xkeyid > NTP_MAXKEY)) {
    32563294                keyid_t cookie;
    32573295
    32583296                /*
     
    32843322        if (mask == NULL) {
    32853323                HTONL_FP(&xmt_tx, &xpkt.xmt);
    32863324        }
     3325
    32873326        authlen = authencrypt(xkeyid, (u_int32 *)&xpkt, sendlen);
    32883327        sendlen += authlen;
     3328
    32893329#ifdef OPENSSL
    32903330        if (xkeyid > NTP_MAXKEY)
    32913331                authtrust(xkeyid, 0);
  • new file ntp-samba/ntpd/ntp_signd.c

    Only in ntp-samba/ntpd: ntp_signd.c
    Only in ntp-dev-4.2.5p125/ntpdc: nl.pl
    Only in ntp-samba/scripts: calc_tickadj
    Only in ntp-samba/scripts: checktime
    Only in ntp-samba/scripts: freq_adj
    Only in ntp-samba/scripts: html2man
    Only in ntp-samba/scripts: Makefile
    Only in ntp-samba/scripts: mkver
    Only in ntp-samba/scripts: ntpsweep
    Only in ntp-samba/scripts: ntptrace
    Only in ntp-samba/scripts: ntpver
    Only in ntp-samba/scripts: ntp-wait
    Only in ntp-samba/scripts: plot_summary
    Only in ntp-samba/scripts: summary
    Only in ntp-samba: stamp-h1
    - +  
     1/* Copyright 2008, Red Hat, Inc.
     2   Copyright 2008, Andrew Tridgell.
     3   Licenced under the same terms as NTP itself.
     4 */
     5#ifdef HAVE_CONFIG_H
     6#include <config.h>
     7#endif
     8
     9#ifdef HAVE_NTP_SIGND
     10
     11#include "ntpd.h"
     12#include "ntp_io.h"
     13#include "ntp_stdlib.h"
     14#include "ntp_unixtime.h"
     15#include "ntp_control.h"
     16#include "ntp_string.h"
     17
     18#include <stdio.h>
     19#include <stddef.h>
     20#ifdef HAVE_LIBSCF_H
     21#include <libscf.h>
     22#include <unistd.h>
     23#endif /* HAVE_LIBSCF_H */
     24
     25#include <sys/un.h>
     26
     27/* socket routines by tridge - from junkcode.samba.org */
     28
     29/*
     30  connect to a unix domain socket
     31*/
     32static int
     33ux_socket_connect(const char *name)
     34{
     35        int fd;
     36        struct sockaddr_un addr;
     37        if (!name) {
     38                return -1;
     39        }
     40
     41        memset(&addr, 0, sizeof(addr));
     42        addr.sun_family = AF_UNIX;
     43        strncpy(addr.sun_path, name, sizeof(addr.sun_path));
     44
     45        fd = socket(AF_UNIX, SOCK_STREAM, 0);
     46        if (fd == -1) {
     47                return -1;
     48        }
     49       
     50        if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
     51                close(fd);
     52                return -1;
     53        }
     54
     55        return fd;
     56}
     57
     58
     59/*
     60  keep writing until its all sent
     61*/
     62static int
     63write_all(int fd, const void *buf, size_t len)
     64{
     65        size_t total = 0;
     66        while (len) {
     67                int n = write(fd, buf, len);
     68                if (n <= 0) return total;
     69                buf = n + (char *)buf;
     70                len -= n;
     71                total += n;
     72        }
     73        return total;
     74}
     75
     76/*
     77  keep reading until its all read
     78*/
     79static int
     80read_all(int fd, void *buf, size_t len)
     81{
     82        size_t total = 0;
     83        while (len) {
     84                int n = read(fd, buf, len);
     85                if (n <= 0) return total;
     86                buf = n + (char *)buf;
     87                len -= n;
     88                total += n;
     89        }
     90        return total;
     91}
     92
     93/*
     94  send a packet in length prefix format
     95*/
     96static int
     97send_packet(int fd, const char *buf, uint32_t len)
     98{
     99        uint32_t net_len = htonl(len);
     100        if (write_all(fd, &net_len, sizeof(net_len)) != sizeof(net_len)) return -1;
     101        if (write_all(fd, buf, len) != len) return -1; 
     102        return 0;
     103}
     104
     105/*
     106  receive a packet in length prefix format
     107*/
     108static int
     109recv_packet(int fd, char **buf, uint32_t *len)
     110{
     111        if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1;
     112        *len = ntohl(*len);
     113        (*buf) = malloc(*len);
     114        if (!*buf) {
     115                return -1;
     116        }
     117        if (read_all(fd, *buf, *len) != *len) {
     118                free(*buf);
     119                return -1;
     120        }
     121        return 0;
     122}
     123
     124void
     125send_via_ntp_signd(
     126        struct recvbuf *rbufp,  /* receive packet pointer */
     127        int     xmode,
     128        keyid_t xkeyid,
     129        int flags,
     130        struct pkt  *xpkt
     131        )
     132{
     133       
     134        /* We are here because it was detected that the client
     135         * sent an all-zero signature, and we therefore know
     136         * it's windows trying to talk to an AD server
     137         *
     138         * Because we don't want to dive into Samba's secrets
     139         * database just to find the long-term kerberos key
     140         * that is re-used as the NTP key, we instead hand the
     141         * packet over to Samba to sign, and return to us.
     142         *
     143         * The signing method Samba will use is described by
     144         * Microsoft in MS-SNTP, found here:
     145         * http://msdn.microsoft.com/en-us/library/cc212930.aspx
     146         */
     147       
     148        int fd, sendlen;
     149        struct samba_key_in {
     150                uint32_t version;
     151                uint32_t op;
     152                uint32_t packet_id;
     153                uint32_t key_id_le;
     154                struct pkt pkt;
     155        } samba_pkt;
     156       
     157        struct samba_key_out {
     158                uint32_t version;
     159                uint32_t op;
     160                uint32_t packet_id;
     161                struct pkt pkt;
     162        } samba_reply;
     163       
     164        char full_socket[256];
     165
     166        char *reply = NULL;
     167        uint32_t reply_len;
     168       
     169        memset(&samba_pkt, 0, sizeof(samba_pkt));
     170        samba_pkt.op = 0; /* Sign message */
     171        /* This will be echoed into the reply - a different
     172         * impelementation might want multiple packets
     173         * awaiting signing */
     174
     175        samba_pkt.packet_id = 1;
     176
     177        /* Swap the byte order back - it's actually little
     178         * endian on the wire, but it was read above as
     179         * network byte order */
     180        samba_pkt.key_id_le = htonl(xkeyid);
     181        samba_pkt.pkt = *xpkt;
     182
     183        snprintf(full_socket, sizeof(full_socket), "%s/socket", ntp_signd_socket);
     184
     185        fd = ux_socket_connect(full_socket);
     186        /* Only continue with this if we can talk to Samba */
     187        if (fd != -1) {
     188                /* Send old packet to Samba, expect response */
     189                /* Packet to Samba is quite simple:
     190                   All values BIG endian except key ID as noted
     191                   [packet size as BE] - 4 bytes
     192                   [protocol version (0)] - 4 bytes
     193                   [packet ID] - 4 bytes
     194                   [operation (sign message=0)] - 4 bytes
     195                   [key id] - LITTLE endian (as on wire) - 4 bytes
     196                   [message to sign] - as marshalled, without signature
     197                */
     198                       
     199                if (send_packet(fd, (char *)&samba_pkt, offsetof(struct samba_key_in, pkt) + LEN_PKT_NOMAC) != 0) {
     200                        /* Huh?  could not talk to Samba... */
     201                        close(fd);
     202                        return;
     203                }
     204                       
     205                if (recv_packet(fd, &reply, &reply_len) != 0) {
     206                        if (reply) {
     207                                free(reply);
     208                        }
     209                        close(fd);
     210                        return;
     211                }
     212                /* Return packet is also simple:
     213                   [packet size] - network byte order - 4 bytes
     214                   [protocol version (0)] network byte order - - 4 bytes
     215                   [operation (signed success=3, failure=4)] network byte order - - 4 byte
     216                   (optional) [signed message] - as provided before, with signature appended
     217                */
     218                       
     219                if (reply_len <= sizeof(samba_reply)) {
     220                        memcpy(&samba_reply, reply, reply_len);
     221                        if (ntohl(samba_reply.op) == 3 && reply_len >  offsetof(struct samba_key_out, pkt)) {
     222                                sendlen = reply_len - offsetof(struct samba_key_out, pkt);
     223                                xpkt = &samba_reply.pkt;
     224                                sendpkt(&rbufp->recv_srcadr, rbufp->dstadr, 0, xpkt, sendlen);
     225#ifdef DEBUG
     226                                if (debug)
     227                                        printf(
     228                                                "transmit ntp_signd packet: at %ld %s->%s mode %d keyid %08x len %d\n",
     229                                                current_time, ntoa(&rbufp->dstadr->sin),
     230                                                ntoa(&rbufp->recv_srcadr), xmode, xkeyid, sendlen);
     231#endif
     232                        }
     233                }
     234               
     235                if (reply) {
     236                        free(reply);
     237                }
     238                close(fd);
     239               
     240        }
     241}
     242#endif
Note: See TracBrowser for help on using the repository browser.