audit_user.c revision 5707ed5dae2bfdea4300de098ba2fa4d22d86f41
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Interfaces to audit_user(4) (/etc/security/audit_user)
*/
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <synch.h>
#include <nss_dbdefs.h>
#include <stdlib.h>
static int use_nsswitch = 1;
/*
* Externs from libnsl
*/
extern void _setauuser(void);
extern void _endauuser(void);
int *);
void
{
(void) mutex_lock(&mutex_userfile);
if (use_nsswitch)
_setauuser();
else if (au_user_file) {
(void) fseek(au_user_file, 0L, 0);
}
(void) mutex_unlock(&mutex_userfile);
}
void
{
(void) mutex_lock(&mutex_userfile);
if (use_nsswitch)
_endauuser();
else if (au_user_file) {
(void) fclose(au_user_file);
au_user_file = NULL;
}
(void) mutex_unlock(&mutex_userfile);
}
{
static au_user_ent_t au_user_entry;
/* initialize au_user_entry structure */
return (getauuserent_r(&au_user_entry));
}
{
char *s, input[256];
(void) mutex_lock(&mutex_userfile);
if (use_nsswitch) {
char buf[NSS_BUFLEN_AUDITUSER];
int errp = 0;
(void) mutex_unlock(&mutex_userfile);
}
/* open audit user file if it isn't already */
if (!au_user_file)
(void) mutex_unlock(&mutex_userfile);
return (NULL);
}
if (input[0] != '#') {
if ((*s == '\0') || (*s == '#')) {
continue;
}
found = 1;
s = input;
/* parse login name */
i = strcspn(s, ":");
s[i] = '\0';
s = &s[i+1];
/* parse first mask */
i = strcspn(s, ":");
s[i] = '\0';
if (getauditflagsbin(s,
&au_user_entry->au_always) < 0)
error = 1;
s = &s[i+1];
/* parse second mask */
i = strcspn(s, "\n\0");
s[i] = '\0';
if (getauditflagsbin(s,
&au_user_entry->au_never) < 0)
error = 1;
break;
}
}
(void) mutex_unlock(&mutex_userfile);
return (au_user_entry);
} else {
return (NULL);
}
}
getauusernam(char *name)
{
static au_user_ent_t u;
/* initialize au_user_entry structure */
return (getauusernam_r(&u, name));
}
{
if (use_nsswitch) {
char buf[NSS_BUFLEN_AUDITUSER];
int errp = 0;
return ((au_user_ent_t *)NULL);
}
&errp);
return (auuserstr2ent(u, tmp));
}
while (getauuserent_r(u) != NULL) {
return (u);
}
}
return ((au_user_ent_t *)NULL);
}
static au_user_ent_t *
{
return (NULL);
return (NULL);
}
}
return (ue);
}
#ifdef DEBUG
void
{
char *empty = "empty";
char *bad = "bad flags";
char always[256];
char never[256];
int retval;
printf("NULL\n");
return;
}
}
#endif /* DEBUG */