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 , 15 years ago | |
---|---|
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 92 92 int requested_key; 93 93 int revoke; 94 94 queue *trusted_key_list; 95 char *ntp_signd_socket; 95 96 }; 96 97 97 98 struct filegen_node { -
include/ntpd.h
diff -ur ntp-dev-4.2.5p125/include/ntpd.h ntp-samba/include/ntpd.h
old new 259 259 extern int config_priority; 260 260 #endif 261 261 262 extern char const *ntp_signd_socket; 263 262 264 /* ntp_control.c */ 263 265 extern int num_ctl_traps; 264 266 extern keyid_t ctl_auth_keyid; /* keyid used for authenticating write requests */ … … 471 473 extern struct refclock *refclock_conf[]; /* refclock configuration table */ 472 474 extern u_char num_refclock_conf; 473 475 #endif 476 477 /* ntp_signd.c */ 478 #ifdef HAVE_NTP_SIGND 479 extern void 480 send_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 447 447 #ifdef OPENSSL 448 448 #define FLAG_ASSOC 0x4000 /* autokey request */ 449 449 #endif /* OPENSSL */ 450 #define FLAG_ADKEY 0x00010000 /* Authenticated (or wants reply to be authenticated) using AD authentication */ 450 451 451 452 /* 452 453 * 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 65 65 ntp_crypto.c ntp_filegen.c \ 66 66 ntp_intres.c ntp_loopfilter.c ntp_monitor.c ntp_peer.c \ 67 67 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 \ 69 69 ppsapi_timepps.h \ 70 70 refclock_acts.c refclock_arbiter.c refclock_arc.c refclock_as2201.c \ 71 71 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 148 148 #endif 149 149 150 150 const char *config_file; 151 const char *ntp_signd_socket; 151 152 #ifdef HAVE_NETINFO 152 153 struct netinfo_config_state *config_netinfo = NULL; 153 154 int check_netinfo = 1; … … 276 277 my_config.auth.crypto_cmd_list = NULL; 277 278 my_config.auth.keys = NULL; 278 279 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 279 285 my_config.auth.requested_key = 0; 280 286 my_config.auth.revoke = 0; 281 287 my_config.auth.trusted_key_list = NULL; … … 795 801 { "crypto", T_Crypto, NO_ARG }, 796 802 { "keys", T_Keys, SINGLE_ARG }, 797 803 { "keysdir", T_Keysdir, SINGLE_ARG }, 804 { "ntpsigndsocket", T_NtpSignDsocket, SINGLE_ARG }, 798 805 { "requestkey", T_Requestkey, NO_ARG }, 799 806 { "revoke", T_Revoke, NO_ARG }, 800 807 { "trustedkey", T_Trustedkey, NO_ARG }, … … 1000 1007 if (my_config.auth.keysdir) 1001 1008 keysdir = my_config.auth.keysdir; 1002 1009 1010 /* ntp_signd_socket Command */ 1011 if (my_config.auth.ntp_signd_socket) 1012 ntp_signd_socket = my_config.auth.ntp_signd_socket; 1013 1003 1014 #ifdef OPENSSL 1004 1015 if (cryptosw) { 1005 1016 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 155 155 %token T_Novolley 156 156 %token T_Ntp 157 157 %token T_Ntpport 158 %token T_NtpSignDsocket 158 159 %token T_Orphan 159 160 %token T_Panic 160 161 %token T_Peer … … 432 433 { my_config.auth.requested_key = $2; } 433 434 | T_Trustedkey integer_list 434 435 { my_config.auth.trusted_key_list = $2; } 436 | T_NtpSignDsocket T_String 437 { my_config.auth.ntp_signd_socket = $2; } 435 438 ; 436 439 437 440 crypto_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 128 128 static void clock_combine (struct peer **, int); 129 129 static void peer_xmit (struct peer *); 130 130 static void fast_xmit (struct recvbuf *, int, keyid_t, 131 char *);131 char *, int); 132 132 static void clock_update (struct peer *); 133 133 static int default_get_precision (void); 134 134 static int peer_unfit (struct peer *); … … 311 311 int authlen; /* offset of MAC field */ 312 312 int is_authentic = 0; /* cryptosum ok */ 313 313 int retcode = AM_NOMATCH; /* match code */ 314 int flags = 0; /* flags with details about the authentication */ 314 315 keyid_t skeyid = 0; /* key IDs */ 315 316 u_int32 opcode = 0; /* extension field opcode */ 316 317 struct sockaddr_storage *dstadr_sin; /* active runway */ … … 324 325 keyid_t pkeyid = 0, tkeyid = 0; /* key IDs */ 325 326 #endif /* OPENSSL */ 326 327 328 static unsigned char zero_key[16]; 329 327 330 /* 328 331 * Monitor the packet and get restrictions. Note that the packet 329 332 * length for control and private mode packets must be checked … … 480 483 return; /* rate exceeded */ 481 484 482 485 if (hismode == MODE_CLIENT) 483 fast_xmit(rbufp, MODE_SERVER, skeyid, "RATE" );486 fast_xmit(rbufp, MODE_SERVER, skeyid, "RATE", 0); 484 487 else 485 fast_xmit(rbufp, MODE_ACTIVE, skeyid, "RATE" );488 fast_xmit(rbufp, MODE_ACTIVE, skeyid, "RATE", 0); 486 489 return; /* rate exceeded */ 487 490 } 488 491 … … 535 538 * is zero, acceptable outcomes of y are NONE and OK. If x is 536 539 * one, the only acceptable outcome of y is OK. 537 540 */ 541 538 542 if (has_mac == 0) { 539 543 is_authentic = AUTH_NONE; /* not required */ 540 544 #ifdef DEBUG … … 555 559 stoa(&rbufp->recv_srcadr), hismode, skeyid, 556 560 authlen + has_mac, is_authentic); 557 561 #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 558 581 } else { 559 582 #ifdef OPENSSL 560 583 /* … … 696 719 if (AUTH(restrict_mask & RES_DONTTRUST, 697 720 is_authentic)) { 698 721 fast_xmit(rbufp, MODE_SERVER, skeyid, 699 NULL);722 NULL, flags); 700 723 } else if (is_authentic == AUTH_ERROR) { 701 fast_xmit(rbufp, MODE_SERVER, 0, NULL );724 fast_xmit(rbufp, MODE_SERVER, 0, NULL, 0); 702 725 sys_badauth++; 703 726 } else { 704 727 sys_restricted++; … … 733 756 * crypto-NAK, as that would not be useful. 734 757 */ 735 758 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); 737 760 return; /* hooray */ 738 761 739 762 /* … … 888 911 is_authentic)) { 889 912 #ifdef OPENSSL 890 913 if (crypto_flags && skeyid > NTP_MAXKEY) 891 fast_xmit(rbufp, MODE_ACTIVE, 0, NULL );914 fast_xmit(rbufp, MODE_ACTIVE, 0, NULL, 0); 892 915 #endif /* OPENSSL */ 893 916 sys_restricted++; 894 917 return; /* access denied */ … … 904 927 * This is for drat broken Windows clients. See 905 928 * Microsoft KB 875424 for preferred workaround. 906 929 */ 907 fast_xmit(rbufp, MODE_PASSIVE, skeyid, NULL );930 fast_xmit(rbufp, MODE_PASSIVE, skeyid, NULL, flags); 908 931 #else /* WINTIME */ 909 932 sys_restricted++; 910 933 #endif /* WINTIME */ … … 938 961 } 939 962 break; 940 963 964 941 965 /* 942 966 * Process regular packet. Nothing special. 943 967 */ … … 1090 1114 peer->flash |= TEST5; /* bad auth */ 1091 1115 peer->badauth++; 1092 1116 if (hismode == MODE_ACTIVE || hismode == MODE_PASSIVE) 1093 fast_xmit(rbufp, MODE_ACTIVE, 0, NULL );1117 fast_xmit(rbufp, MODE_ACTIVE, 0, NULL, 0); 1094 1118 if (peer->flags & FLAG_PREEMPT) { 1095 1119 unpeer(peer); 1096 1120 return; … … 3159 3183 struct recvbuf *rbufp, /* receive packet pointer */ 3160 3184 int xmode, /* receive mode */ 3161 3185 keyid_t xkeyid, /* transmit key ID */ 3162 char *mask /* kiss code */ 3186 char *mask, /* kiss code */ 3187 int flags /* Flags to indicate signing behaviour */ 3163 3188 ) 3164 3189 { 3165 3190 struct pkt xpkt; /* transmit packet structure */ … … 3220 3245 HTONL_FP(&rbufp->recv_time, &xpkt.rec); 3221 3246 } 3222 3247 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 3223 3261 /* 3224 3262 * If the received packet contains a MAC, the transmitted packet 3225 3263 * is authenticated and contains a MAC. If not, the transmitted … … 3252 3290 * source-destination-key ID combination. 3253 3291 */ 3254 3292 #ifdef OPENSSL 3255 if ( xkeyid > NTP_MAXKEY) {3293 if (!(flags & FLAG_ADKEY) && (xkeyid > NTP_MAXKEY)) { 3256 3294 keyid_t cookie; 3257 3295 3258 3296 /* … … 3284 3322 if (mask == NULL) { 3285 3323 HTONL_FP(&xmt_tx, &xpkt.xmt); 3286 3324 } 3325 3287 3326 authlen = authencrypt(xkeyid, (u_int32 *)&xpkt, sendlen); 3288 3327 sendlen += authlen; 3328 3289 3329 #ifdef OPENSSL 3290 3330 if (xkeyid > NTP_MAXKEY) 3291 3331 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 */ 32 static int 33 ux_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 */ 62 static int 63 write_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 */ 79 static int 80 read_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 */ 96 static int 97 send_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 */ 108 static int 109 recv_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 124 void 125 send_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.