+ /* If no srvtab file exists, fail immediatly. This will make
+ * login _much_ quicker on systems with sporadical contact with
+ * the outside world.
+ * We should really change the semantics for enabling kerberos.
+ */
+ if((fd = open(KEYFILE, O_RDONLY, 0)) < 0)
+ return 1;
+ close(fd);
+
/*
* Root logins don't use Kerberos (or at least shouldn't be
* sending kerberos passwords around in cleartext), so don't
@@ -119,8 +128,8 @@
*/
- if (chown(TKT_FILE, pw->pw_uid, pw->pw_gid) < 0)
- syslog(LOG_ERR, "chown tkfile (%s): %m", TKT_FILE);
+ /*
+ * Set the owner of the ticket file to root but bail if someone
+ * has nefariously swapped a link in place of the file.
+ */
+ fd = open(TKT_FILE, O_RDWR|O_NOFOLLOW, 0);
+ if (fd == -1) {
+ syslog(LOG_ERR, "unable to open ticket file: %m");
+ dest_tkt();
+ return (1);
+ }
+ if (fchown(fd, pw->pw_uid, pw->pw_gid) < 0)
+ syslog(LOG_ERR, "fchown tkfile (%s): %m", TKT_FILE);
+ close(fd);
+ /* Don't bother with Kerberos if there is no srvtab file */
+ if ((fd = open(KEYFILE, O_RDONLY, 0)) < 0)
+ return (1);
+ close(fd);
+
if (koktologin(username, lrealm, user) && !uid) {
(void)fprintf(stderr, "kerberos su: not in %s's ACL.\n", user);
return (1);
@@ -407,11 +413,22 @@
return (1);
}
- if (chown(krbtkfile, uid, -1) < 0) {
- warn("chown");
+ /*
+ * Set the owner of the ticket file to root but bail if someone
+ * has nefariously swapped a link in place of the file.
+ */
+ fd = open(krbtkfile, O_RDWR|O_NOFOLLOW, 0);
+ if (fd == -1) {
+ warn("unable to open ticket file");
+ (void)unlink(krbtkfile);
+ return (1);
+ }
+ if (fchown(fd, uid, -1) < 0) {
+ warn("fchown");
(void)unlink(krbtkfile);
return (1);
}
+ close(fd);