#include <afs/ktc.h>
#include <afs/token.h>
+#define KERBEROS_APPLE_DEPRECATED(x)
#include <krb5.h>
-#if defined(HAVE_ET_COM_ERR_H)
-#include <et/com_err.h>
+#ifdef HAVE_COM_ERR_H
+# include <com_err.h>
+#elif HAVE_ET_COM_ERR_H
+# include <et/com_err.h>
+#elif HAVE_KRB5_COM_ERR_H
+# include <krb5/com_err.h>
#else
-#include <com_err.h>
+# error No com_err.h? We need some kind of com_err.h
#endif
#ifndef HAVE_KERBEROSV_HEIM_ERR_H
}
afs_dprintf("We've deduced that we need to authenticate"
" to realm %s.\n", realm_of_cell);
+ status = get_credv5(context, AFSKEY, cell->name,
+ realm_of_cell, v5cred);
}
- status = get_credv5(context, AFSKEY, cell->name,
- realm_of_cell, v5cred);
}
/* If the realm and cell name match, then try without an
* structure which should be freed by the caller.
* @param[out[ userPtr
* A string containing the principal of the user to whom the token was
- * issued. This is a malloc'd block which should be freed by the caller.
+ * issued. This is a malloc'd block which should be freed by the caller,
+ * if set.
*
* @returns
* 0 on success, an error value upon failure
static int
rxkad_build_native_token(krb5_context context, krb5_creds *v5cred,
struct ktc_tokenUnion **tokenPtr, char **userPtr) {
- char username[BUFSIZ];
+ char username[BUFSIZ]="";
struct ktc_token token;
int status;
#ifdef HAVE_NO_KRB5_524
char k4inst[INST_SZ];
char k4realm[REALM_SZ];
#endif
+ void *inkey = get_cred_keydata(v5cred);
+ size_t inkey_sz = get_cred_keylen(v5cred);
afs_dprintf("Using Kerberos V5 ticket natively\n");
(char *) &k4inst,
(char *) &k4realm);
if (status) {
- afs_com_err(progname, status, "while converting principal "
- "to Kerberos V4 format");
- return AKLOG_KERBEROS;
- }
- strcpy (username, k4name);
- if (k4inst[0]) {
- strcat (username, ".");
- strcat (username, k4inst);
+ if (!noprdb)
+ afs_com_err(progname, status,
+ "while converting principal to Kerberos V4 format");
+ } else {
+ strcpy (username, k4name);
+ if (k4inst[0]) {
+ strcat (username, ".");
+ strcat (username, k4inst);
+ }
}
#else
len = min(get_princ_len(context, v5cred->client, 0),
token.kvno = RXKAD_TKT_TYPE_KERBEROS_V5;
token.startTime = v5cred->times.starttime;;
token.endTime = v5cred->times.endtime;
- memcpy(&token.sessionKey, get_cred_keydata(v5cred),
- get_cred_keylen(v5cred));
+ if (tkt_DeriveDesKey(get_creds_enctype(v5cred), inkey, inkey_sz,
+ &token.sessionKey) != 0) {
+ return RXKADBADKEY;
+ }
token.ticketLen = v5cred->ticket.length;
memcpy(token.ticket, v5cred->ticket.data, token.ticketLen);
return status;
}
- *userPtr = strdup(username);
+ if (username[0] != '\0')
+ *userPtr = strdup(username);
return 0;
}
* structure which should be freed by the caller.
* @param[out[ userPtr
* A string containing the principal of the user to whom the token was
- * issued. This is a malloc'd block which should be freed by the caller.
+ * issued. This is a malloc'd block which should be freed by the caller,
+ * if set.
*
* @returns
* 0 on success, an error value upon failure
* be freed by the caller.
* @parma[out] authuser
* A string containing the principal of the user to whom the token was
- * issued. This is a malloc'd block which should be freed by the caller.
+ * issued. This is a malloc'd block which should be freed by the caller,
+ * if set.
* @param[out] foreign
* Whether the user is considered as 'foreign' to the realm of the cell.
*
/* We now have the username, plus the realm name, so stitch them together
* to give us the name that the ptserver will know the user by */
- if (realmUsed == NULL) {
+ if (realmUsed == NULL || username == NULL) {
*authuser = username;
username = NULL;
*foreign = 0;
} else {
- asprintf(authuser, "%s@%s", username, realmUsed);
+ if (asprintf(authuser, "%s@%s", username, realmUsed) < 0) {
+ fprintf(stderr, "%s: Out of memory building PTS name\n", progname);
+ *authuser = NULL;
+ status = AKLOG_MISC;
+ goto out;
+ }
*foreign = 1;
}
noprdb = 1;
#endif
- if (noprdb) {
+ if (username == NULL) {
+ afs_dprintf("Not resolving name to id\n");
+ }
+ else if (noprdb) {
afs_dprintf("Not resolving name %s to id (-noprdb set)\n", username);
}
else {
}
}
- afs_dprintf("Setting tokens. %s @ %s \n", username, cellconf.name);
+ if (username) {
+ afs_dprintf("Setting tokens. %s @ %s\n",
+ username, cellconf.name);
+ } else {
+ afs_dprintf("Setting tokens for cell %s\n", cellconf.name);
+ }
#ifndef AFS_AIX51_ENV
/* on AIX 4.1.4 with AFS 3.4a+ if a write is not done before
* this routine, it will not add the token. It is not clear what
* is going on here! So we will do the following operation.
* On AIX 5, it causes the parent program to die, so we won't.
+ * We don't care about the return value, but need to collect it
+ * to avoid compiler warnings.
*/
- write(2,"",0); /* dummy write */
+ if (write(2,"",0) < 0) {
+ /* dummy write, don't care */
+ }
#endif
token_setPag(token, afssetpag);
status = ktc_SetTokenEx(token);
static char path[MAXPATHLEN + 1];
static char pathtocheck[MAXPATHLEN + 1];
- int link = FALSE; /* Is this a symbolic link? */
+ ssize_t link; /* Return value from readlink */
char linkbuf[MAXPATHLEN + 1];
char tmpbuf[MAXPATHLEN + 1];
else
last_comp = elast_comp;
}
- while(link);
+ while(link > 0);
return(pathtocheck);
}
char *defaultpath = "~/Library/Preferences/edu.mit.Kerberos:/Library/Preferences/edu.mit.Kerberos";
#endif
filepath = getenv("KRB5_CONFIG");
- asprintf(&newpath, "%s:%s/krb5-weak.conf",
- filepath ? filepath : defaultpath,
- AFSDIR_CLIENT_ETC_DIRPATH);
- setenv("KRB5_CONFIG", newpath, 1);
+
+ /* only fiddle with KRB5_CONFIG if krb5-weak.conf actually exists */
+ if (asprintf(&newpath, "%s/krb5-weak.conf",
+ AFSDIR_CLIENT_ETC_DIRPATH) < 0)
+ newpath = NULL;
+ if (newpath != NULL && access(newpath, R_OK) == 0) {
+ free(newpath);
+ newpath = NULL;
+ if (asprintf(&newpath, "%s:%s/krb5-weak.conf",
+ filepath ? filepath : defaultpath,
+ AFSDIR_CLIENT_ETC_DIRPATH) < 0)
+ newpath = NULL;
+ else
+ setenv("KRB5_CONFIG", newpath, 1);
+ }
#endif
krb5_init_context(&context);
#if defined(KRB5_PROG_ETYPE_NOSUPP) && !(defined(HAVE_KRB5_ENCTYPE_ENABLE) || defined(HAVE_KRB5_ALLOW_WEAK_CRYPTO))
- free(newpath);
+ if (newpath)
+ free(newpath);
if (filepath)
setenv("KRB5_CONFIG", filepath, 1);
else
}
else {
cmode++;
- strlcpy(cell, argv[i], sizeof(path));
+ strlcpy(cell, argv[i], sizeof(cell));
}
}
else
krb5_keytab_entry new[1];
int best = -1;
memset(new, 0, sizeof *new);
- if ((code == krb5_kt_start_seq_get(context, kt, cursor))) {
+ if ((code = krb5_kt_start_seq_get(context, kt, cursor))) {
afs_com_err(progname, code, "while starting keytab scan");
goto cleanup;
}
increds.client = client_principal;
increds.times.endtime = 0;
- /* Ask for DES since that is what V4 understands */
- get_creds_enctype((&increds)) = ENCTYPE_DES_CBC_CRC;
+ if (do524)
+ /* Ask for DES since that is what V4 understands */
+ get_creds_enctype((&increds)) = ENCTYPE_DES_CBC_CRC;
if (keytab) {
int allowed_enctypes[] = {