]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testcreds.c
8e3c878a15a79d9f340868e9a309221b7683ad86
2 * HTTP credentials test program for CUPS.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include "cups-private.h"
24 * 'main()' - Main entry.
27 int /* O - Exit status */
28 main(int argc
, /* I - Number of command-line arguments */
29 char *argv
[]) /* I - Command-line arguments */
31 http_t
*http
; /* HTTP connection */
32 char scheme
[HTTP_MAX_URI
], /* Scheme from URI */
33 hostname
[HTTP_MAX_URI
], /* Hostname from URI */
34 username
[HTTP_MAX_URI
], /* Username:password from URI */
35 resource
[HTTP_MAX_URI
]; /* Resource from URI */
36 int port
; /* Port number from URI */
37 http_trust_t trust
; /* Trust evaluation for connection */
38 cups_array_t
*hcreds
, /* Credentials from connection */
39 *tcreds
; /* Credentials from trust store */
40 char hinfo
[1024], /* String for connection credentials */
41 tinfo
[1024]; /* String for trust store credentials */
42 static const char *trusts
[] = /* Trust strings */
43 { "OK", "Invalid", "Changed", "Expired", "Renewed", "Unknown" };
47 * Check command-line...
52 puts("Usage: ./testcreds hostname");
53 puts(" ./testcreds https://hostname[:port]");
57 if (!strncmp(argv
[1], "https://", 8))
60 * Connect to the host and validate credentials...
63 if (httpSeparateURI(HTTP_URI_CODING_MOST
, argv
[1], scheme
, sizeof(scheme
), username
, sizeof(username
), hostname
, sizeof(hostname
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
65 printf("ERROR: Bad URI \"%s\".\n", argv
[1]);
69 if ((http
= httpConnect2(hostname
, port
, NULL
, AF_UNSPEC
, HTTP_ENCRYPTION_ALWAYS
, 1, 30000, NULL
)) == NULL
)
71 printf("ERROR: Unable to connect to \"%s\" on port %d: %s\n", hostname
, port
, cupsLastErrorString());
75 puts("HTTP Credentials:");
76 if (!httpCopyCredentials(http
, &hcreds
))
78 trust
= httpCredentialsGetTrust(hcreds
, hostname
);
80 httpCredentialsString(hcreds
, hinfo
, sizeof(hinfo
));
82 printf(" Certificate Count: %d\n", cupsArrayCount(hcreds
));
83 if (trust
== HTTP_TRUST_OK
)
86 printf(" Trust: %s (%s)\n", trusts
[trust
], cupsLastErrorString());
87 printf(" Expiration: %s\n", httpGetDateString(httpCredentialsGetExpiration(hcreds
)));
88 printf(" IsValidName: %d\n", httpCredentialsAreValidForName(hcreds
, hostname
));
89 printf(" String: \"%s\"\n", hinfo
);
91 httpFreeCredentials(hcreds
);
94 puts(" Not present (error).");
101 * Load stored credentials...
104 strlcpy(hostname
, argv
[1], sizeof(hostname
));
107 printf("Trust Store for \"%s\":\n", hostname
);
109 if (!httpLoadCredentials(NULL
, &tcreds
, hostname
))
111 httpCredentialsString(tcreds
, tinfo
, sizeof(tinfo
));
113 printf(" Certificate Count: %d\n", cupsArrayCount(tcreds
));
114 printf(" Expiration: %s\n", httpGetDateString(httpCredentialsGetExpiration(tcreds
)));
115 printf(" IsValidName: %d\n", httpCredentialsAreValidForName(tcreds
, hostname
));
116 printf(" String: \"%s\"\n", tinfo
);
118 httpFreeCredentials(tcreds
);
121 puts(" Not present.");