#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
#error "Must have either keyblock or session member of krb5_creds"
#endif
-#ifdef AFS_DARWIN110_ENV
-#define HAVE_NO_KRB5_524 /* MITKerberosShim logs but returns success */
+/* MITKerberosShim logs but returns success */
+#if !defined(HAVE_KRB5_524_CONV_PRINCIPAL) || defined(AFS_DARWIN110_ENV) || (!defined(HAVE_KRB5_524_CONVERT_CREDS) && !defined(HAVE_KRB524_CONVERT_CREDS_KDC))
+#define HAVE_NO_KRB5_524
#elif !defined(HAVE_KRB5_524_CONVERT_CREDS) && defined(HAVE_KRB524_CONVERT_CREDS_KDC)
#define krb5_524_convert_creds krb524_convert_creds_kdc
-#elif !defined(HAVE_KRB5_524_CONVERT_CREDS) && !defined(HAVE_KRB524_CONVERT_CREDS_KDC)
-#define HAVE_NO_KRB5_524
#endif
#if USING_HEIMDAL
if (strncmp(str, "unknown", strlen("unknown")) == 0) {
#ifdef HAVE_KRB5_SVC_GET_MSG
krb5_svc_get_msg(code,&str);
-#elif defined(HAVE_ERROR_MESSAGE)
- str = error_message(code);
+#elif defined(HAVE_KRB5_GET_ERROR_MESSAGE)
+ krb5_context context;
+ krb5_init_context(&context);
+ str = krb5_get_error_message(context, code);
+ krb5_free_context(context);
#else
; /* IRIX apparently has neither: use the string we have */
#endif
{
cellinfo_t *new_cellinfo;
- if ((new_cellinfo = (cellinfo_t *)malloc(sizeof(cellinfo_t))))
+ if ((new_cellinfo = malloc(sizeof(cellinfo_t))))
memcpy(new_cellinfo, cellinfo, sizeof(cellinfo_t));
return ((char *)new_cellinfo);
}
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
afs_com_err(progname, status, "while getting AFS tickets");
#ifdef KRB5_CC_NOT_KTYPE
if (status == KRB5_CC_NOT_KTYPE) {
- fprintf(stderr, "allow_weak_enctypes may be required in the Kerberos configuration\n");
+ fprintf(stderr, "allow_weak_crypto may be required in the Kerberos configuration\n");
}
#endif
status = AKLOG_KERBEROS;
* 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];
- struct ktc_tokenUnion *token;
- struct token_rxkad *rxkadToken;
+ char username[BUFSIZ]="";
+ struct ktc_token token;
+ int status;
#ifdef HAVE_NO_KRB5_524
char *p;
int len;
#else
- int status;
char k4name[ANAME_SZ];
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),
}
#endif
- token = malloc(sizeof(struct ktc_tokenUnion));
- if (token == NULL)
- return ENOMEM;
-
- memset(token, 0, sizeof(struct ktc_tokenUnion));
+ memset(&token, 0, sizeof(struct ktc_token));
- token->at_type = AFSTOKEN_UNION_KAD;
- rxkadToken = &token->ktc_tokenUnion_u.at_kad;
+ token.kvno = RXKAD_TKT_TYPE_KERBEROS_V5;
+ token.startTime = v5cred->times.starttime;;
+ token.endTime = v5cred->times.endtime;
+ 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);
- rxkadToken->rk_kvno = RXKAD_TKT_TYPE_KERBEROS_V5;
- rxkadToken->rk_begintime = v5cred->times.starttime;;
- rxkadToken->rk_endtime = v5cred->times.endtime;
- memcpy(&rxkadToken->rk_key, get_cred_keydata(v5cred),
- get_cred_keylen(v5cred));
- rxkadToken->rk_ticket.rk_ticket_len = v5cred->ticket.length;
- rxkadToken->rk_ticket.rk_ticket_val = malloc(v5cred->ticket.length);
- if (rxkadToken->rk_ticket.rk_ticket_val == NULL) {
- free(token);
- return ENOMEM;
+ status = token_importRxkadViceId(tokenPtr, &token, 0);
+ if (status) {
+ return status;
}
- memcpy(rxkadToken->rk_ticket.rk_ticket_val, v5cred->ticket.data,
- rxkadToken->rk_ticket.rk_ticket_len);
- *tokenPtr = token;
- *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
struct ktc_tokenUnion **tokenPtr, char **userPtr) {
CREDENTIALS cred;
char username[BUFSIZ];
- struct ktc_tokenUnion *token;
- struct token_rxkad *rxkadToken;
+ struct ktc_token token;
int status;
*tokenPtr = NULL;
strcat (username, cred.pinst);
}
- token = malloc(sizeof(struct ktc_tokenUnion));
- if (token == NULL)
- return ENOMEM;
- memset(token, 0, sizeof(struct ktc_tokenUnion));
-
- token->at_type = AFSTOKEN_UNION_KAD;
+ memset(&token, 0, sizeof(struct ktc_token));
- rxkadToken = &token->ktc_tokenUnion_u.at_kad;
- rxkadToken->rk_kvno = cred.kvno;
- rxkadToken->rk_begintime = cred.issue_date;
+ token.kvno = cred.kvno;
+ token.startTime = cred.issue_date;
/*
* It seems silly to go through a bunch of contortions to
* extract the expiration time, when the v5 credentials already
* Note that this isn't a security hole, as the expiration time
* is also contained in the encrypted token
*/
- rxkadToken->rk_endtime = v5cred->times.endtime;
- memcpy(&rxkadToken->rk_key, cred.session, 8);
- rxkadToken->rk_ticket.rk_ticket_len = cred.ticket_st.length;
- rxkadToken->rk_ticket.rk_ticket_val = malloc(cred.ticket_st.length);
- if (rxkadToken->rk_ticket.rk_ticket_val == NULL) {
- free(token);
- return ENOMEM;
+ token.endTime = v5cred->times.endtime;
+ memcpy(&token.sessionKey, cred.session, 8);
+ token.ticketLen = cred.ticket_st.length;
+ memcpy(token.ticket, cred.ticket_st.dat, token.ticketLen);
+
+ status = token_importRxkadViceId(tokenPtr, &token, 0);
+ if (status) {
+ return status;
}
- memcpy(rxkadToken->rk_ticket.rk_ticket_val, cred.ticket_st.dat,
- rxkadToken->rk_ticket.rk_ticket_len);
- *tokenPtr = token;
*userPtr = strdup(username);
return 0;
* 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.
*
char *realmUsed = NULL;
char *username = NULL;
int status;
- size_t len;
*token = NULL;
*authuser = NULL;
/* 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 {
- len = strlen(username)+strlen(realmUsed)+2;
- *authuser = malloc(len);
- snprintf(*authuser, len, "%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 {
#endif /* ALLOW_REGISTER */
if ((status == 0) && (viceId != ANONYMOUSID)) {
- rxkadToken->ktc_tokenUnion_u.at_kad.rk_viceid = viceId;
- token_replaceToken(token, rxkadToken);
+ status = token_setRxkadViceId(rxkadToken, viceId);
+ if (status) {
+ fprintf(stderr, "Error %d setting rxkad ViceId\n", status);
+ status = AKLOG_SUCCESS;
+ } else {
+ token_replaceToken(token, rxkadToken);
+ }
}
}
- 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);
out:
if (rxkadToken) {
- free(rxkadToken->ktc_tokenUnion_u.at_kad.rk_ticket.rk_ticket_val);
- free(rxkadToken);
+ token_freeToken(&rxkadToken);
}
if (local_cell)
struct ViceIoctl vio;
char cellname[BUFSIZ];
- memset(our_file, 0, sizeof(our_file));
- strcpy(our_file, file);
+ strlcpy(our_file, file, sizeof(our_file));
if ((last_component = strrchr(our_file, DIR))) {
*last_component++ = 0;
vio.out = cellname;
if (!pioctl(file, VIOC_FILE_CELL_NAME, &vio, 1)) {
- strcat(cellname, VOLMARKERSTRING);
- strcat(cellname, mountpoint + 1);
+ strlcat(cellname, VOLMARKERSTRING, sizeof(cellname));
+ strlcat(cellname, mountpoint + 1, sizeof(cellname));
memset(mountpoint + 1, 0, size - 1);
strcpy(mountpoint + 1, cellname);
}
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];
if (origpath) {
memset(path, 0, sizeof(path));
memset(pathtocheck, 0, sizeof(pathtocheck));
- strcpy(path, origpath);
+ strlcpy(path, origpath, sizeof(path));
last_comp = path;
symlinkcount = 0;
return(NULL);
? elast_comp - last_comp : strlen(last_comp);
strncat(pathtocheck, last_comp, len);
memset(linkbuf, 0, sizeof(linkbuf));
- if ((link = (readlink(pathtocheck, linkbuf,
- sizeof(linkbuf)) > 0))) {
+ link = readlink(pathtocheck, linkbuf, sizeof(linkbuf)-1);
+
+ if (link > 0) {
+ linkbuf[link] = '\0'; /* NUL terminate string */
+
if (++symlinkcount > MAXSYMLINKS) {
fprintf(stderr, "%s: %s\n", progname, strerror(ELOOP));
exit(AKLOG_BADPATH);
}
+
memset(tmpbuf, 0, sizeof(tmpbuf));
if (elast_comp)
- strcpy(tmpbuf, elast_comp);
+ strlcpy(tmpbuf, elast_comp, sizeof(tmpbuf));
if (linkbuf[0] == DIR) {
/*
* If this is a symbolic link to an absolute path,
else
last_comp = elast_comp;
}
- while(link);
+ while(link > 0);
return(pathtocheck);
}
/* Initialize */
if (path[0] == DIR)
- strcpy(pathtocheck, path);
+ strlcpy(pathtocheck, path, sizeof(pathtocheck));
else {
if (getcwd(pathtocheck, sizeof(pathtocheck)) == NULL) {
fprintf(stderr, "Unable to find current working directory:\n");
exit(AKLOG_BADPATH);
}
else {
- strcat(pathtocheck, DIRSTRING);
- strcat(pathtocheck, path);
+ strlcat(pathtocheck, DIRSTRING, sizeof(pathtocheck));
+ strlcat(pathtocheck, path, sizeof(pathtocheck));
}
}
next_path(pathtocheck);
/* Go on to the next level down the path */
while ((nextpath = next_path(NULL))) {
- strcpy(pathtocheck, nextpath);
+ strlcpy(pathtocheck, nextpath, sizeof(pathtocheck));
afs_dprintf("Checking directory %s\n", pathtocheck);
/*
* If this is an afs mountpoint, determine what cell from
#if defined(KRB5_PROG_ETYPE_NOSUPP) && !(defined(HAVE_KRB5_ENCTYPE_ENABLE) || defined(HAVE_KRB5_ALLOW_WEAK_CRYPTO))
{
char *filepath = NULL, *newpath = NULL;
- filepath = getenv("KRB5_CONFIG");
- if (!filepath) {
- int slen;
#ifndef AFS_DARWIN_ENV
- slen = strlen(filepath)+strlen(":/etc/krb5.conf")+1;
- newpath = malloc(slen);
- snprintf(newpath, slen, "%s:/etc/krb5.conf", filepath);
+ char *defaultpath = "/etc/krb5.conf:/etc/krb5/krb5.conf";
#else
- slen = strlen("~/Library/Preferences/edu.mit.Kerberos:/Library/Preferences/edu.mit.Kerberos:")+strlen(AFSDIR_CLIENT_ETC_DIRPATH)+strlen("/krb5-weak.conf")+1;
- newpath = malloc(slen);
- snprintf(newpath, slen, "~/Library/Preferences/edu.mit.Kerberos:/Library/Preferences/edu.mit.Kerberos:%s/krb5-weak.conf", AFSDIR_CLIENT_ETC_DIRPATH);
+ char *defaultpath = "~/Library/Preferences/edu.mit.Kerberos:/Library/Preferences/edu.mit.Kerberos";
#endif
+ filepath = getenv("KRB5_CONFIG");
+
+ /* 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);
}
- 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
(strcmp(argv[i], "-c") == 0)) && !pmode)
if (++i < argc) {
cmode++;
- strcpy(cell, argv[i]);
+ strlcpy(cell, argv[i], sizeof(cell));
}
else
usage();
(strcmp(argv[i], "-p") == 0)) && !cmode)
if (++i < argc) {
pmode++;
- strcpy(path, argv[i]);
+ strlcpy(path, argv[i], sizeof(path));
}
else
usage();
if (strchr(argv[i], DIR) || (strcmp(argv[i], ".") == 0) ||
(strcmp(argv[i], "..") == 0)) {
pmode++;
- strcpy(path, argv[i]);
+ strlcpy(path, argv[i], sizeof(path));
}
else {
cmode++;
- strcpy(cell, argv[i]);
+ strlcpy(cell, argv[i], sizeof(cell));
}
}
else
if (((i + 1) < argc) && (strcmp(argv[i + 1], "-k") == 0)) {
i+=2;
if (i < argc)
- strcpy(realm, argv[i]);
+ strlcpy(realm, argv[i], sizeof(realm));
else
usage();
}
FILE *f;
char fcell[100], xlog_path[512];
- strcpy(xlog_path, pwd->pw_dir);
- strcat(xlog_path, "/.xlog");
+ strlcpy(xlog_path, pwd->pw_dir, sizeof(xlog_path));
+ strlcat(xlog_path, "/.xlog", sizeof(xlog_path));
if ((stat(xlog_path, &sbuf) == 0) &&
((f = fopen(xlog_path, "r")) != NULL)) {
EncTicketPart enc_tkt_reply[1];
krb5_address address[30];
krb5_addresses faddr[1];
- int temp_vno[1];
+ unsigned int temp_vno[1];
time_t temp_time[2];
#else
krb5_ticket ticket_reply[1];
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;
}
}
} /* crypto block */
ticket_reply->enc_part.etype = deref_entry_enctype(entry);
- ticket_reply->enc_part.kvno = temp_vno;
+ ticket_reply->enc_part.kvno = (void *)temp_vno;
*ticket_reply->enc_part.kvno = entry->vno;
ticket_reply->tkt_vno = 5;
#else
if ((r = krb5_build_principal(context, &increds.server,
strlen(realm), realm,
name,
- (inst && strlen(inst)) ? inst : (void *) NULL,
- (void *) NULL))) {
+ (inst && strlen(inst)) ? inst : NULL,
+ NULL))) {
return r;
}
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[] = {