.\" 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
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#include <ctype.h>
#include <keyutils.h>
#include <krb5/krb5.h>
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;
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);