pam_set_item.c revision 110503
1189251Ssam/*- 2189251Ssam * Copyright (c) 2002 Networks Associates Technology, Inc. 3281806Srpaulo * All rights reserved. 4189251Ssam * 5252726Srpaulo * This software was developed for the FreeBSD Project by ThinkSec AS and 6252726Srpaulo * Network Associates Laboratories, the Security Research Division of 7189251Ssam * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 8189251Ssam * ("CBOSS"), as part of the DARPA CHATS research program. 9189251Ssam * 10189251Ssam * Redistribution and use in source and binary forms, with or without 11189251Ssam * modification, are permitted provided that the following conditions 12189251Ssam * are met: 13189251Ssam * 1. Redistributions of source code must retain the above copyright 14281806Srpaulo * notice, this list of conditions and the following disclaimer. 15281806Srpaulo * 2. Redistributions in binary form must reproduce the above copyright 16281806Srpaulo * notice, this list of conditions and the following disclaimer in the 17281806Srpaulo * documentation and/or other materials provided with the distribution. 18281806Srpaulo * 3. The name of the author may not be used to endorse or promote 19281806Srpaulo * products derived from this software without specific prior written 20281806Srpaulo * permission. 21281806Srpaulo * 22281806Srpaulo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23281806Srpaulo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24281806Srpaulo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25351611Scy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26351611Scy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27351611Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28351611Scy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29351611Scy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30351611Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31351611Scy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32351611Scy * SUCH DAMAGE. 33351611Scy * 34351611Scy * $P4: //depot/projects/openpam/lib/pam_set_item.c#17 $ 35351611Scy */ 36351611Scy 37351611Scy#include <sys/param.h> 38351611Scy 39351611Scy#include <stdlib.h> 40351611Scy#include <string.h> 41351611Scy 42351611Scy#include <security/pam_appl.h> 43351611Scy 44351611Scy#include "openpam_impl.h" 45351611Scy 46351611Scy/* 47351611Scy * XSSO 4.2.1 48351611Scy * XSSO 6 page 60 49351611Scy * 50351611Scy * Set authentication information 51351611Scy */ 52351611Scy 53351611Scyint 54351611Scypam_set_item(pam_handle_t *pamh, 55189251Ssam int item_type, 56189251Ssam const void *item) 57189251Ssam{ 58189251Ssam void **slot, *tmp; 59189251Ssam size_t nsize, osize; 60189251Ssam 61189251Ssam ENTERI(item_type); 62189251Ssam if (pamh == NULL) 63189251Ssam RETURNC(PAM_SYSTEM_ERR); 64346981Scy slot = &pamh->item[item_type]; 65346981Scy switch (item_type) { 66346981Scy case PAM_SERVICE: 67346981Scy case PAM_USER: 68189251Ssam case PAM_AUTHTOK: 69189251Ssam case PAM_OLDAUTHTOK: 70189251Ssam case PAM_TTY: 71189251Ssam case PAM_RHOST: 72189251Ssam case PAM_RUSER: 73189251Ssam case PAM_USER_PROMPT: 74189251Ssam case PAM_AUTHTOK_PROMPT: 75189251Ssam case PAM_OLDAUTHTOK_PROMPT: 76189251Ssam if (item != NULL) 77189251Ssam nsize = strlen(item) + 1; 78189251Ssam if (*slot != NULL) 79189251Ssam osize = strlen(*slot) + 1; 80189251Ssam break; 81189251Ssam case PAM_REPOSITORY: 82189251Ssam osize = nsize = sizeof(struct pam_repository); 83189251Ssam break; 84189251Ssam case PAM_CONV: 85189251Ssam osize = nsize = sizeof(struct pam_conv); 86189251Ssam break; 87189251Ssam default: 88346981Scy RETURNC(PAM_SYMBOL_ERR); 89346981Scy } 90346981Scy if (*slot != NULL) { 91346981Scy memset(*slot, 0xd0, osize); 92189251Ssam free(*slot); 93189251Ssam } 94189251Ssam if (item != NULL) { 95189251Ssam if ((tmp = malloc(nsize)) == NULL) 96189251Ssam RETURNC(PAM_BUF_ERR); 97189251Ssam memcpy(tmp, item, nsize); 98189251Ssam } else { 99189251Ssam tmp = NULL; 100189251Ssam } 101189251Ssam *slot = tmp; 102189251Ssam RETURNC(PAM_SUCCESS); 103189251Ssam} 104189251Ssam 105189251Ssam/* 106189251Ssam * Error codes: 107189251Ssam * 108189251Ssam * PAM_SYMBOL_ERR 109189251Ssam * PAM_SYSTEM_ERR 110189251Ssam * PAM_BUF_ERR 111189251Ssam */ 112189251Ssam 113189251Ssam/** 114189251Ssam * The =pam_set_item function sets the item specified by the =item_type 115189251Ssam * argument to a copy of the object pointed to by the =item argument. 116189251Ssam * The item is stored in the PAM context specified by the =pamh argument. 117189251Ssam * See =pam_get_item for a list of recognized item types. 118189251Ssam */ 119189251Ssam