]> www.infradead.org Git - users/dhowells/kafs-client.git/commitdiff
aklog: Make cell argument optional
authorDavid Howells <dhowells@redhat.com>
Tue, 16 Apr 2019 15:48:35 +0000 (16:48 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 16 Apr 2019 16:05:48 +0000 (17:05 +0100)
Make cell argument to aklog-kafs optional, reading the cell from
/proc/net/afs/rootcell if not given.

Also support --help.

Signed-off-by: David Howells <dhowells@redhat.com>
man/aklog-kafs.1
src/aklog-kafs.c

index e6187e95f305b69456127d7176dc759e404a012d..c2b69ca715e213071adbb6451434abb9f087538b 100644 (file)
@@ -7,25 +7,28 @@
 .\" as published by the Free Software Foundation; either version
 .\" 2 of the License, or (at your option) any later version.
 .\"
-.TH AKLOG 1 "9 Feb 2018" Linux "AFS Kerberos authentication"
+.TH AKLOG-KAFS 1 "16 Apr 2019" Linux "AFS Kerberos authentication"
 .SH NAME
-aklog \- AFS Kerberos authentication tool
+aklog-kafs \- AFS Kerberos authentication tool
 .SH SYNOPSIS
-\fBaklog\fR <cell> [<realm>]
+\fBaklog-kafs\fR [<cell> [<realm>]]
 .P
 .B
 *** NOTE THE ABOVE IS PROVISIONAL AND IS LIKELY TO CHANGE ***
 .R
 .SH DESCRIPTION
 This program is used to get an authentication ticket from Kerberos that can be
-used by the kAFS filesystem to perform authenticated and encrypted accesses to
-the server.  Without this only unencrypted anonymous accesses can be made.
+used by the in-kernel AFS filesystem (kAFS) to perform authenticated and
+encrypted accesses to the server.  Without this only unencrypted anonymous
+accesses can be made.
 .P
 Before calling this, the \fBkinit\fR program or similar should be invoked to
 authenticate with the appropriate Kerberos server.
 .SH ARGUMENTS
 .IP <cell>
-This is the name of the cell with which the ticket is intended to be used.
+This is the name of the cell with which the ticket is intended to be used.  If
+not given, the name of the default cell will be read from
+\fB/proc/net/afs/rootcell\fR and used instead.
 .IP <realm>
 This is the name of the Kerberos realm from which the ticket will be obtained.
 .SH ERRORS
index 27e4dc2867cbb6db4a4965250e9db125d1161b3b..4cee50994b572570272e7e39a51e9021734c9a51 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <ctype.h>
 #include <keyutils.h>
 #include <krb5/krb5.h>
@@ -247,6 +248,42 @@ key_too_short:
        exit(1);
 }
 
+/*
+ * Read the name of default cell.
+ */
+static char *get_default_cell(void)
+{
+       static const char rootcell[] = "/proc/net/afs/rootcell";
+       ssize_t n;
+       char buf[260], *nl, *cell;
+       int fd;
+
+       fd = open(rootcell, O_RDONLY);
+       OSERROR(fd, rootcell);
+       n = read(fd, buf, sizeof(buf) - 2);
+       OSERROR(n, rootcell);
+       close(n);
+       if (n == 0)
+               goto unset;
+
+       buf[n] = 0;
+       nl = memchr(buf, '\n', n);
+       if (nl == buf)
+               goto unset;
+       *nl = 0;
+
+       cell = strdup(buf);
+       OSZERROR(cell, "strdup");
+       return cell;
+
+unset:
+       fprintf(stderr, "error: The default cell is not set\n");
+       exit(1);
+}
+
+/*
+ *
+ */
 int main(int argc, char **argv)
 {
        char *cell, *realm, *princ, *desc, *p;
@@ -258,14 +295,19 @@ int main(int argc, char **argv)
        krb5_ccache cc;
        krb5_creds search_cred, *creds;
 
-       if (argc < 2 || argc > 3) {
-               fprintf(stderr, "Usage: aklog <cell> [<realm>]\n");
+       if (argc < 1 || argc > 3 ||
+           (argc == 2 && strcmp(argv[1], "--help") == 0)) {
+               fprintf(stderr, "Usage: aklog-kafs [<cell> [<realm>]]\n");
                exit(1);
        }
 
-       cell = argv[1];
+       if (argc == 1)
+               cell = get_default_cell();
+       else
+               cell = argv[1];
+
        if (argc == 3) {
-               realm = strdup(argv[3]);
+               realm = strdup(argv[2]);
                OSZERROR(realm, "strdup");
        } else {
                realm = strdup(cell);