|
Packit Service |
09cdfc |
/*
|
|
Packit Service |
09cdfc |
Unix SMB/CIFS implementation.
|
|
Packit Service |
09cdfc |
replacement routines for broken systems
|
|
Packit Service |
09cdfc |
Copyright (C) Andrew Tridgell 1992-1998
|
|
Packit Service |
09cdfc |
Copyright (C) Jelmer Vernooij 2005-2008
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
** NOTE! The following LGPL license applies to the replace
|
|
Packit Service |
09cdfc |
** library. This does NOT imply that all of Samba is released
|
|
Packit Service |
09cdfc |
** under the LGPL
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
This library is free software; you can redistribute it and/or
|
|
Packit Service |
09cdfc |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
09cdfc |
License as published by the Free Software Foundation; either
|
|
Packit Service |
09cdfc |
version 3 of the License, or (at your option) any later version.
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
This library is distributed in the hope that it will be useful,
|
|
Packit Service |
09cdfc |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
09cdfc |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
09cdfc |
Lesser General Public License for more details.
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
09cdfc |
License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
#include <sys/types.h>
|
|
Packit Service |
09cdfc |
#include <string.h>
|
|
Packit Service |
09cdfc |
#include <pwd.h>
|
|
Packit Service |
09cdfc |
#include "util.h"
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/* glibc doesn't have strlcpy, strlcat. Ensure we do. JRA. We
|
|
Packit Service |
09cdfc |
* don't link to libreplace so need them here. */
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/* like strncpy but does not 0 fill the buffer and always null
|
|
Packit Service |
09cdfc |
* terminates. bufsize is the size of the destination buffer */
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
#ifndef HAVE_STRLCPY
|
|
Packit Service |
09cdfc |
size_t strlcpy(char *d, const char *s, size_t bufsize)
|
|
Packit Service |
09cdfc |
{
|
|
Packit Service |
09cdfc |
size_t len = strlen(s);
|
|
Packit Service |
09cdfc |
size_t ret = len;
|
|
Packit Service |
09cdfc |
if (bufsize <= 0) return 0;
|
|
Packit Service |
09cdfc |
if (len >= bufsize) len = bufsize-1;
|
|
Packit Service |
09cdfc |
memcpy(d, s, len);
|
|
Packit Service |
09cdfc |
d[len] = 0;
|
|
Packit Service |
09cdfc |
return ret;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
#endif
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/* like strncat but does not 0 fill the buffer and always null
|
|
Packit Service |
09cdfc |
* terminates. bufsize is the length of the buffer, which should
|
|
Packit Service |
09cdfc |
* be one more than the maximum resulting string length */
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
#ifndef HAVE_STRLCAT
|
|
Packit Service |
09cdfc |
size_t strlcat(char *d, const char *s, size_t bufsize)
|
|
Packit Service |
09cdfc |
{
|
|
Packit Service |
09cdfc |
size_t len1 = strlen(d);
|
|
Packit Service |
09cdfc |
size_t len2 = strlen(s);
|
|
Packit Service |
09cdfc |
size_t ret = len1 + len2;
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
if (len1+len2 >= bufsize) {
|
|
Packit Service |
09cdfc |
if (bufsize < (len1+1)) {
|
|
Packit Service |
09cdfc |
return ret;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
len2 = bufsize - (len1+1);
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
if (len2 > 0) {
|
|
Packit Service |
09cdfc |
memcpy(d+len1, s, len2);
|
|
Packit Service |
09cdfc |
d[len1+len2] = 0;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
return ret;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
#endif
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/* caller frees username if necessary */
|
|
Packit Service |
09cdfc |
char *
|
|
Packit Service |
09cdfc |
getusername(uid_t uid)
|
|
Packit Service |
09cdfc |
{
|
|
Packit Service |
09cdfc |
char *username = NULL;
|
|
Packit Service |
09cdfc |
struct passwd *password = getpwuid(uid);
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
if (password)
|
|
Packit Service |
09cdfc |
username = password->pw_name;
|
|
Packit Service |
09cdfc |
return username;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
|