示例#1
0
文件: klog.c 项目: openafs/openafs
krb5_error_code
klog_prompter(krb5_context context,
    void *a,
    const char *name,
    const char *banner,
    int num_prompts,
    krb5_prompt prompts[])
{
    krb5_error_code code;
    int i;
    struct kp_arg *kparg = (struct kp_arg *) a;
    size_t length;

    code = krb5_prompter_posix(context, a, name, banner, num_prompts, prompts);
    if (code) return code;
    for (i = 0; i < num_prompts; ++i) {
	if (klog_is_pass_prompt(i, context, prompts)) {
	    length = prompts[i].reply->length;
	    if (length > kparg->allocated - 1)
		length = kparg->allocated - 1;
	    memcpy(kparg->pstore, prompts[i].reply->data, length);
	    kparg->pstore[length] = 0;
	    *kparg->pp = kparg->pstore;
	}
    }
    return 0;
}
示例#2
0
static kim_error kim_ui_cli_read_string (kim_string   *out_string, 
                                         kim_boolean   in_hide_reply, 
                                         const char   *in_format, ...)
{
    kim_error err = KIM_NO_ERROR;
    krb5_context k5context = NULL;
    krb5_prompt prompts[1];
    char prompt_string [BUFSIZ];
    krb5_data reply_data;
    char reply_string [BUFSIZ];
    
    if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !in_format ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    
    if (!err) {
        err = krb5_init_context (&k5context);
    }
    
    if (!err) {
        unsigned int count;
        va_list args;
        
        va_start (args, in_format);
        count = vsnprintf (prompt_string, sizeof (prompt_string), 
                                  in_format, args);
        va_end (args);
        
        if (count > sizeof (prompt_string)) {
            kim_debug_printf ("%s(): WARNING! Prompt should be %d characters\n", 
                              __FUNCTION__, count);
            prompt_string [sizeof (prompt_string) - 1] = '\0';
        }
    }
    
    if (!err) {
        /* Build the prompt structures */
        prompts[0].prompt        = prompt_string;
        prompts[0].hidden        = in_hide_reply;
        prompts[0].reply         = &reply_data;
        prompts[0].reply->data   = reply_string;
        prompts[0].reply->length = sizeof (reply_string);
        
        err = krb5_prompter_posix (k5context, NULL, NULL, NULL, 1, prompts);
        if (err == KRB5_LIBOS_PWDINTR || err == KRB5_LIBOS_CANTREADPWD) { 
            err = check_error (KIM_USER_CANCELED_ERR); 
        }
    }
    
    if (!err) {
        err = kim_string_create_from_buffer (out_string, 
                                             prompts[0].reply->data, 
                                             prompts[0].reply->length);
    }
    
    if (k5context) { krb5_free_context (k5context); }
    
    return check_error (err);
}
示例#3
0
krb5_error_code
klog_prompter(krb5_context context,
    void *a,
    const char *name,
    const char *banner,
    int num_prompts,
    krb5_prompt prompts[])
{
    krb5_error_code code;
    int i, type;
#if !defined(USING_HEIMDAL) && defined(HAVE_KRB5_GET_PROMPT_TYPES)
    krb5_prompt_type *types;
#endif
    struct kp_arg *kparg = (struct kp_arg *) a;
    code = krb5_prompter_posix(context, a, name, banner, num_prompts, prompts);
    if (code) return code;
#if !defined(USING_HEIMDAL) && defined(HAVE_KRB5_GET_PROMPT_TYPES)
    if ((types = krb5_get_prompt_types(context)))
#endif
    for (i = 0; i < num_prompts; ++i) {
#if !defined(USING_HEIMDAL) 
#if defined(HAVE_KRB5_GET_PROMPT_TYPES)
	type = types[i];
#elif defined(HAVE_KRB5_PROMPT_TYPE)	
	type = prompts[i].type;
#else
	/* AIX 5.3 krb5_get_prompt_types is missing. Um... */
	type = ((i == 1)&&(num_prompts == 2)) ? 
	  KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN : KRB5_PROMPT_TYPE_PASSWORD;
#endif
#else
	type = prompts[i].type;
#endif
#if 0
	printf ("i%d t%d <%.*s>\n", i, type, prompts[i].reply->length,
		prompts[i].reply->data);
#endif
	switch(type) {
	case KRB5_PROMPT_TYPE_PASSWORD:
	case KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN:
	    memcpy(kparg->pstore, prompts[i].reply->data, prompts[i].reply->length);
	    kparg->pstore[prompts[i].reply->length] = 0;
	    *kparg->pp = kparg->pstore;
	}
    }
    return 0;
}
示例#4
0
static char *ask_password(krb5_context krbctx)
{
    krb5_prompt ap_prompts[2];
    krb5_data k5d_pw0;
    krb5_data k5d_pw1;
    char pw0[256];
    char pw1[256];
    char *password;

    k5d_pw0.length = sizeof(pw0);
    k5d_pw0.data = pw0;
    ap_prompts[0].prompt = _("New Principal Password");
    ap_prompts[0].hidden = 1;
    ap_prompts[0].reply = &k5d_pw0;

    k5d_pw1.length = sizeof(pw1);
    k5d_pw1.data = pw1;
    ap_prompts[1].prompt = _("Verify Principal Password");
    ap_prompts[1].hidden = 1;
    ap_prompts[1].reply = &k5d_pw1;

    krb5_prompter_posix(krbctx, NULL,
                NULL, NULL,
                2, ap_prompts);

    if (strcmp(pw0, pw1)) {
        fprintf(stderr, _("Passwords do not match!"));
        return NULL;
    }

    password = malloc(k5d_pw0.length + 1);
    if (!password) return NULL;
    memcpy(password, pw0, k5d_pw0.length);
    password[k5d_pw0.length] = '\0';

    return password;
}
示例#5
0
kim_error kim_ui_cli_auth_prompt (kim_ui_context      *in_context,
                                  kim_identity         in_identity,
                                  kim_prompt_type      in_type,
                                  kim_boolean          in_allow_save_reply, 
                                  kim_boolean          in_hide_reply, 
                                  kim_string           in_title,
                                  kim_string           in_message,
                                  kim_string           in_description,
                                  char               **out_reply,
                                  kim_boolean         *out_save_reply)
{
    kim_error err = KIM_NO_ERROR;
    
    if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !out_reply  ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    /* in_title, in_message or in_description may be NULL */
    
    if (!err) {
        if (in_type == kim_prompt_type_password) {
            kim_string enter_password_format = NULL;
            kim_string identity_string = NULL;
            
            err = kim_os_string_create_localized (&enter_password_format, 
                                                  "Please enter the password for %s");
            
            if (!err) {
                err = kim_identity_get_display_string (in_identity, 
                                                       &identity_string);
            }
            
            if (!err) {
                err = kim_ui_cli_read_string ((kim_string *) out_reply, 
                                              1, enter_password_format, 
                                              identity_string);
            }    
            
            kim_string_free (&identity_string);
            kim_string_free (&enter_password_format);
            
        } else {
            krb5_context k5context = NULL;
            krb5_prompt prompts[1];
            krb5_data reply_data;
            char reply_string [BUFSIZ];

            prompts[0].prompt        = (char *) in_description;
            prompts[0].hidden        = in_hide_reply;
            prompts[0].reply         = &reply_data;
            prompts[0].reply->data   = reply_string;
            prompts[0].reply->length = sizeof (reply_string);

            err = krb5_init_context (&k5context);

            if (!err) {
                err = krb5_prompter_posix (k5context, in_context, in_title, 
                                           in_message, 1, prompts);
                if (err == KRB5_LIBOS_PWDINTR || err == KRB5_LIBOS_CANTREADPWD) { 
                    err = check_error (KIM_USER_CANCELED_ERR); 
                }
            }
            
            if (!err) {
                err = kim_string_create_from_buffer ((kim_string *) out_reply, 
                                                     prompts[0].reply->data, 
                                                     prompts[0].reply->length);
                if (!err) {
                    /* always allow password saving */
                    *out_save_reply = (in_allow_save_reply && 
                                       in_type == kim_prompt_type_password);
                }
            }
            
            if (k5context) { krb5_free_context (k5context); }
        }
    }
    
    return check_error (err);
}