if (fgets(buf, sizeof(buf), stdin) == NULL) { krb5_free_principal (context, entry.principal); return 0; }
if (fgets(buf, sizeof(buf), stdin) == NULL) goto out;
kt_add(int argc, char **argv){    krb5_error_code ret;    krb5_keytab_entry entry;    char buf[128];    char *principal_string = NULL;    int kvno = -1;    char *enctype_string = NULL;    krb5_enctype enctype;    char *password_string = NULL;    int salt_flag = 1;    int random_flag = 0;    int help_flag = 0;    struct getargs args[] = {	{ "principal", 'p', arg_string, NULL, "principal of key", "principal"},	{ "kvno", 'V', arg_integer, NULL, "key version of key" },	{ "enctype", 'e', arg_string, NULL, "encryption type of key" },	{ "password", 'w', arg_string, NULL, "password for key"},	{ "salt", 's',	arg_negative_flag, NULL, "no salt" },	{ "random",  'r', arg_flag, NULL, "generate random key" },	{ "help", 'h', arg_flag, NULL }    };    int num_args = sizeof(args) / sizeof(args[0]);    int optind = 0;    int i = 0;    args[i++].value = &principal_string;    args[i++].value = &kvno;    args[i++].value = &enctype_string;    args[i++].value = &password_string;    args[i++].value = &salt_flag;    args[i++].value = &random_flag;    args[i++].value = &help_flag;    if(getarg(args, num_args, argc, argv, &optind)) {	arg_printusage(args, num_args, "ktutil add", "");	return 0;    }    if(help_flag) {	arg_printusage(args, num_args, "ktutil add", "");	return 0;    }    if(principal_string == NULL) {	printf("Principal: ");	if (fgets(buf, sizeof(buf), stdin) == NULL)	    return 0;	buf[strcspn(buf, "\r\n")] = '\0';	principal_string = buf;    }    ret = krb5_parse_name(context, principal_string, &entry.principal);    if(ret) {	krb5_warn(context, ret, "%s", principal_string);	return 0;    }    if(enctype_string == NULL) {	printf("Encryption type: ");	if (fgets(buf, sizeof(buf), stdin) == NULL) {	    krb5_free_principal (context, entry.principal);	    return 0;	}	buf[strcspn(buf, "\r\n")] = '\0';	enctype_string = buf;    }    ret = krb5_string_to_enctype(context, enctype_string, &enctype);    if(ret) {	int t;	if(sscanf(enctype_string, "%d", &t) == 1)	    enctype = t;	else {	    krb5_warn(context, ret, "%s", enctype_string);	    krb5_free_principal(context, entry.principal);	    return 0;	}    }    if(kvno == -1) {	printf("Key version: ");	if (fgets(buf, sizeof(buf), stdin) == NULL) {	    krb5_free_principal (context, entry.principal);	    return 0;	}	buf[strcspn(buf, "\r\n")] = '\0';	kvno = atoi(buf);    }    if(password_string == NULL && random_flag == 0) {	if(des_read_pw_string(buf, sizeof(buf), "Password: ", 1)) {	    krb5_free_principal (context, entry.principal);	    return 0;	}	password_string = buf;    }    if(password_string) {	if (!salt_flag) {	    krb5_salt salt;	    krb5_data pw;	    salt.salttype         = KRB5_PW_SALT;	    salt.saltvalue.data   = NULL;	    salt.saltvalue.length = 0;	    pw.data = (void*)password_string;	    pw.length = strlen(password_string);	    krb5_string_to_key_data_salt(context, enctype, pw, salt,					 &entry.keyblock);        } else {	    krb5_string_to_key(context, enctype, password_string, 			       entry.principal, &entry.keyblock);	}	memset (password_string, 0, strlen(password_string));    } else {	krb5_generate_random_keyblock(context, enctype, &entry.keyblock);    }    entry.vno = kvno;    entry.timestamp = time (NULL);    ret = krb5_kt_add_entry(context, keytab, &entry);    if(ret)	krb5_warn(context, ret, "add");    krb5_kt_free_entry(context, &entry);    return 0;}