Changeset 101 in openpam for trunk/lib


Ignore:
Timestamp:
Apr 6, 2002, 5:17:44 PM (18 years ago)
Author:
Dag-Erling Smørgrav
Message:

Plug memory leak, reduce differences between these very similar
functions, and {add,tweak} documentation.

Sponsored by: DARPA, NAI Labs

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/pam_get_authtok.c

    r100 r101  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_get_authtok.c#13 $
     34 * $P4: //depot/projects/openpam/lib/pam_get_authtok.c#14 $
    3535 */
    3636
    3737#include <sys/param.h>
     38
     39#include <stdlib.h>
    3840
    3941#include <security/pam_appl.h>
     
    9698        if (r != PAM_SUCCESS)
    9799                return (r);
    98         *authtok = resp;
    99         return (pam_set_item(pamh, item, *authtok));
     100        r = pam_set_item(pamh, pitem, resp);
     101        free(resp);
     102        if (r != PAM_SUCCESS)
     103                return (r);
     104        return (pam_get_item(pamh, pitem, (const void **)authtok));
    100105}
    101106
     
    125130 *
    126131 * The =prompt argument specifies a prompt to use if no token is cached.
    127  * If =NULL, the =PAM_AUTHTOK_PROMPT or =PAM_OLDAUTHTOK_PROMPT item, as
    128  * appropriate, will be used.  If that item is also =NULL, a hardcoded
     132 * If it is =NULL, the =PAM_AUTHTOK_PROMPT or =PAM_OLDAUTHTOK_PROMPT item,
     133 * as appropriate, will be used.  If that item is also =NULL, a hardcoded
    129134 * default prompt will be used.
    130135 *
    131136 * >pam_get_item
     137 * >pam_get_user
    132138 */
  • trunk/lib/pam_get_user.c

    r93 r101  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_get_user.c#10 $
     34 * $P4: //depot/projects/openpam/lib/pam_get_user.c#11 $
    3535 */
    3636
    3737#include <sys/param.h>
     38
     39#include <stdlib.h>
    3840
    3941#include <security/pam_appl.h>
     
    4143
    4244#include "openpam_impl.h"
     45
     46const char user_prompt[] = "Login:";
    4347
    4448/*
     
    5458        const char *prompt)
    5559{
    56         char *p, *resp;
     60        char *resp;
    5761        int r;
    5862
     
    6468                return (PAM_SUCCESS);
    6569        if (prompt == NULL) {
    66                 if (pam_get_item(pamh, PAM_USER_PROMPT,
    67                     (const void **)&p) != PAM_SUCCESS || p == NULL)
    68                         prompt = "Login: ";
     70                r = pam_get_item(pamh, PAM_USER_PROMPT, (const void **)&prompt);
     71                if (r != PAM_SUCCESS || prompt == NULL)
     72                        prompt = user_prompt;
    6973        }
    70         r = pam_prompt(pamh, PAM_PROMPT_ECHO_ON, &resp,
    71             "%s", prompt ? prompt : p);
     74        r = pam_prompt(pamh, PAM_PROMPT_ECHO_ON, &resp, "%s", prompt);
    7275        if (r != PAM_SUCCESS)
    7376                return (r);
    74         *user = resp;
    75         return (pam_set_item(pamh, PAM_USER, *user));
     77        r = pam_set_item(pamh, PAM_USER, resp);
     78        free(resp);
     79        if (r != PAM_SUCCESS)
     80                return (r);
     81        return (pam_get_item(pamh, PAM_USER, (const void **)user));
    7682}
    7783
     
    8490 *      !PAM_SYMBOL_ERR
    8591 */
     92
     93/**
     94 * The =pam_get_user function returns the name of the target user, as
     95 * specified to =pam_start.  If no user was specified, nor set using
     96 * =pam_set_item, =pam_get_user will prompt for a user name.  Either way,
     97 * a pointer to the user name is stored in the location pointed to by the
     98 * =user argument.
     99
     100 * The =prompt argument specifies a prompt to use if no user name is
     101 * cached.  If it is =NULL, the =PAM_USER_PROMPT will be used.  If that
     102 * item is also =NULL, a hardcoded default prompt will be used.
     103 *
     104 * >pam_get_item
     105 * >pam_get_authtok
     106 */
Note: See TracChangeset for help on using the changeset viewer.