2 * Copyright (c) 1995 - 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 /* Tiny program to help debug popper */
49 if(select(s
+1, &fds
, 0, 0, 0) < 0)
51 if(FD_ISSET(0, &fds
)){
52 fgets(cmd
, sizeof(cmd
), stdin
);
53 cmd
[strlen(cmd
) - 1] = '\0';
54 strlcat (cmd
, "\r\n", sizeof(cmd
));
55 write(s
, cmd
, strlen(cmd
));
57 if(FD_ISSET(s
, &fds
)){
58 int n
= read(s
, buf
, sizeof(buf
));
61 fwrite(buf
, n
, 1, stdout
);
67 get_socket (const char *hostname
, int port
)
70 struct addrinfo
*ai
, *a
;
71 struct addrinfo hints
;
72 char portstr
[NI_MAXSERV
];
74 memset (&hints
, 0, sizeof(hints
));
75 hints
.ai_socktype
= SOCK_STREAM
;
76 snprintf (portstr
, sizeof(portstr
), "%d", ntohs(port
));
77 ret
= getaddrinfo (hostname
, portstr
, &hints
, &ai
);
79 errx (1, "getaddrinfo %s: %s", hostname
, gai_strerror (ret
));
81 for (a
= ai
; a
!= NULL
; a
= a
->ai_next
) {
84 s
= socket (a
->ai_family
, a
->ai_socktype
, a
->ai_protocol
);
87 if (connect (s
, a
->ai_addr
, a
->ai_addrlen
) < 0) {
94 err (1, "failed to connect to %s", hostname
);
99 doit_v5 (char *host
, int port
)
102 krb5_context context
;
103 krb5_auth_context auth_context
= NULL
;
104 krb5_principal server
;
105 int s
= get_socket (host
, port
);
107 ret
= krb5_init_context (&context
);
109 errx (1, "krb5_init_context failed: %d", ret
);
111 ret
= krb5_sname_to_principal (context
,
117 warnx ("krb5_sname_to_principal: %s",
118 krb5_get_err_text (context
, ret
));
121 ret
= krb5_sendauth (context
,
135 warnx ("krb5_sendauth: %s",
136 krb5_get_err_text (context
, ret
));
146 static int use_v5
= -1;
148 static char *port_str
;
149 static int do_version
;
152 struct getargs args
[] = {
154 { "krb5", '5', arg_flag
, &use_v5
, "Use Kerberos V5",
157 { "port", 'p', arg_string
, &port_str
, "Use this port",
158 "number-or-service" },
159 { "version", 0, arg_flag
, &do_version
, "Print version",
161 { "help", 0, arg_flag
, &do_help
, NULL
,
168 arg_printusage (args
,
169 sizeof(args
) / sizeof(args
[0]),
176 main(int argc
, char **argv
)
182 setprogname(argv
[0]);
184 if (getarg (args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
,
195 print_version (NULL
);
203 struct servent
*s
= roken_getservbyname (port_str
, "tcp");
210 port
= strtol (port_str
, &ptr
, 10);
211 if (port
== 0 && ptr
== port_str
)
212 errx (1, "Bad port `%s'", port_str
);
218 port
= krb5_getportbyname (NULL
, "kpop", "tcp", 1109);
220 #error must define KRB5
226 ret
= doit_v5 (argv
[0], port
);