const char *script;
int status;
pid_t child_pid;
- char err_buf[ERR_BUF_LEN];
script = getlogindefs_str (variable, NULL);
_exit (1);
}
case -1: /* Error occurs. */
- fprintf (stderr, _("Cannot fork: %s\n"), strerror_r(errno, err_buf, ERR_BUF_LEN));
+ fprintf (stderr, _("Cannot fork: %s\n"), strerror (errno));
return -1;
break;
default: /* Parent. */
int err = errno;
if (err != EINTR)
fprintf (stderr, _("waitpid (%d) failed: %s\n"),
- child_pid, strerror_r(err, err_buf, ERR_BUF_LEN));
+ child_pid, strerror (err));
}
break;
}
{
uid_t use_uid;
gid_t use_gid;
- char err_buf[ERR_BUF_LEN];
if (st->st_uid == old_uid)
use_uid = new_uid;
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- entry, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ entry, strerror (errno));
return -1;
}
}
{
char srcfile[strlen (src) + strlen (entry->d_name) + 2];
char *cp;
- memset(srcfile, 0, sizeof(srcfile));
/* create source and destination filename with full path. */
cp = stpcpy (srcfile, src);
*cp++ = '/';
- strncpy (cp, entry->d_name, strlen(entry->d_name));
+ strcpy (cp, entry->d_name);
if (lstat (srcfile, &st) != 0)
continue;
char *cp;
/* create source and destination filename with full path. */
- memset(srcfile, 0, sizeof(srcfile));
cp = stpcpy (srcfile, src);
*cp++ = '/';
- strncpy (cp, entry->d_name, strlen(entry->d_name));
+ strcpy (cp, entry->d_name);
- memset(dstfile, 0, sizeof(dstfile));
cp = stpcpy (dstfile, dst);
*cp++ = '/';
- strncpy (cp, entry->d_name, strlen(entry->d_name));
+ strcpy (cp, entry->d_name);
if (lstat (srcfile, &st) != 0)
continue;
{
if (mkdir (dstfile, 0) != 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("Cannot create directory `%s': %s\n"),
- dstfile, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dstfile, strerror (errno));
retval = 1;
}
else
preserve_id ? st.st_gid : gid) != 0 ||
chmod (dstfile, st.st_mode & 07777) != 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("Cannot change permissions for `%s': %s\n"),
- dstfile, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dstfile, strerror (errno));
/* An error occured, remove the new subtree. */
remove_dir_rec (dstfile);
retval = 1;
char buffer[4096];
int len = readlink (srcfile, buffer, sizeof (buffer));
- if (len < 0 || len >= 4096)
+ if (len < 0)
retval = 1;
else
{
buffer[len] = '\0';
if (symlink (buffer, dstfile) != 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("Cannot create symlink `%s': %s\n"),
- dstfile, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ dstfile, strerror (errno));
retval = 1;
}
else if (lchown (dstfile,
preserve_id ? st.st_uid : uid,
preserve_id ? st.st_gid : gid) != 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- dstfile, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ dstfile, strerror (errno));
unlink (dstfile);
retval = 1;
}
{
char buffer[4096];
int cnt;
- char err_buf[ERR_BUF_LEN];
while ((cnt = read (src_fd, buffer, sizeof (buffer))) > 0)
{
if (write (dst_fd, buffer, cnt) != cnt)
{
fprintf (stderr, _("Cannot copy `%s': %s\n"),
- srcfile, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ srcfile, strerror (errno));
cnt = -1;
break;
}
chmod (dstfile, st.st_mode & 07777))
{
fprintf (stderr, _("Cannot change permissions for `%s': %s\n"),
- dstfile, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dstfile, strerror (errno));
unlink (dstfile);
retval = 1;
}
char *
date2str (time_t date)
{
- struct tm *tp, tp_buf;
+ struct tm *tp;
char buf[12];
- tp = gmtime_r (&date, &tp_buf);
+ tp = gmtime (&date);
#ifdef HAVE_STRFTIME
strftime (buf, sizeof (buf), "%Y-%m-%d", tp);
#else
else
{
char *cp = alloca (strlen (nswp2->orders[0]) + 1);
- memset(cp, 0, strlen (nswp2->orders[0]) + 1);
- strncpy (cp, nswp2->orders[0], strlen (nswp2->orders[0]));
+ strcpy (cp, nswp2->orders[0]);
cmpptr = cp;
nsw_free (nswp2);
}
write_group_data (group_t *data, int is_locked)
{
int retval = 0;
- char err_buf[ERR_BUF_LEN];
if (data->service == S_LOCAL)
{
int gotit, newgf_fd;
char *cp;
- memset(group_tmp, 0, strlen (files_etc_dir) + strlen (file_tmp) + 1);
- memset(group_orig, 0, strlen (files_etc_dir) + 8);
- memset(group_old, 0, strlen (files_etc_dir) + 12);
-
cp = stpcpy (group_tmp, files_etc_dir);
- strncpy (cp, file_tmp, strlen(file_tmp));
+ strcpy (cp, file_tmp);
cp = stpcpy (group_orig, files_etc_dir);
- strncpy (cp, "/group", strlen("/group"));
+ strcpy (cp, "/group");
cp = stpcpy (group_old, group_orig);
- strncpy (cp, ".old", strlen(".old"));
+ strcpy (cp, ".old");
if ((oldgf = fopen (group_orig, "r")) == NULL)
{
{
fprintf (stderr,
_("Cannot change permissions for `%s': %s\n"),
- group_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ group_tmp, strerror (errno));
fclose (oldgf);
close (newgf_fd);
unlink (group_tmp);
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- group_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ group_tmp, strerror (errno));
fclose (oldgf);
close (newgf_fd);
unlink (group_tmp);
*errnop = ERANGE;
return -1;
}
- memset(buffer, 0, buflen);
- strncpy (buffer, line, buflen);
+ strcpy (buffer, line);
line = buffer;
STRING_FIELD (result->gr_name, ISCOLON, 0);
if (line[0] == '\0' && !strict
case NPD_GECOS:
fprintf (stderr, "\tgecos field: %s\n",
npderr2str (err->npd_code));
- break;
case NPD_SHELL:
fprintf (stderr, "\tshell field: %s\n",
npderr2str (err->npd_code));
NISENTRYLEN(6,obj) = strlen (NISENTRYVAL(6,obj));
}
- snprintf (buf, strlen (obj->zo_name) + strlen (obj->zo_domain) + 10, "%s.%s", obj->zo_name, obj->zo_domain);
+ sprintf (buf, "%s.%s", obj->zo_name, obj->zo_domain);
result = nis_modify_entry (buf, obj, 0);
if (result->status != NIS_SUCCESS)
{
/* Get group of passwd table */
buf = alloca (strlen (data->pw.pw_name) + strlen (domain) + 30);
- snprintf (buf, strlen (data->pw.pw_name) + strlen (domain) + 30,"passwd.org_dir.%s", domain);
+ sprintf (buf, "passwd.org_dir.%s", domain);
result = nis_lookup (buf, 0);
if (result->status != NIS_SUCCESS)
{
}
group = alloca (strlen (NIS_RES_OBJECT(result)->zo_group) + 1);
- memset(group, 0, strlen (NIS_RES_OBJECT(result)->zo_group) + 1);
- strncpy (group, NIS_RES_OBJECT(result)->zo_group, strlen(NIS_RES_OBJECT(result)->zo_group));
+ strcpy (group, NIS_RES_OBJECT(result)->zo_group);
nis_freeresult (result);
/* Get old NIS+ passwd information for caller or parameter. */
- snprintf (buf, strlen (data->pw.pw_name) + strlen (domain) + 30,"[name=%s],passwd.org_dir.%s", data->pw.pw_name, domain);
+ sprintf (buf, "[name=%s],passwd.org_dir.%s", data->pw.pw_name, domain);
result = nis_list (buf, 0, NULL, NULL);
extern int restore_default_context (char *prev_context) __attribute_warn_unused_result__;
#endif
-#define ERR_BUF_LEN 256
-#define BUF_POOL_LEN 16384
-#define BUF_PW_LEN 16384
-
#endif /* __PUBLIC_H__ */
if (*stream == NULL)
{
char *filename = alloca (strlen (files_etc_dir) + strlen (file) + 1);
- memset( filename, 0, strlen (files_etc_dir) + strlen (file) + 1);
- strncpy (filename, files_etc_dir, strlen(files_etc_dir));
- strncat (filename, file, strlen(file));
+ strcpy (filename, files_etc_dir);
+ strcat (filename, file);
*stream = fopen (filename, "r");
if (*stream == NULL)
{
char *filename = alloca (strlen (files_etc_dir) + strlen (file) + 1);
- memset( filename, 0, strlen (files_etc_dir) + strlen (file) + 1);
- strncpy (filename, files_etc_dir, strlen(files_etc_dir));
- strncat (filename, file, strlen(file));
+ strcpy (filename, files_etc_dir);
+ strcat (filename, file);
*stream = fopen (filename, "r");
struct dirent *entry;
DIR *dir = opendir (tree);
int retval = 0;
- char err_buf[ERR_BUF_LEN];
if (dir == NULL)
return -1;
struct stat st;
char *cp;
- memset(srcfile, 0, sizeof(srcfile));
/* create source and destination filename with full path. */
cp = stpcpy (srcfile, tree);
*cp++ = '/';
- strncpy (cp, entry->d_name, strlen(entry->d_name));
+ strcpy (cp, entry->d_name);
if (lstat (srcfile, &st) != 0)
continue;
else if (unlink (srcfile) != 0)
{
fprintf (stderr, _("Cannot remove file `%s': %s\n"),
- srcfile, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ srcfile, strerror (errno));
retval = -1;
}
}
if (rmdir (tree) != 0)
{
fprintf (stderr, _("Cannot remove directory `%s': %s\n"),
- tree, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ tree, strerror (errno));
retval = -1;
}
else
{
char *cp = alloca (strlen (nswp2->orders[0]) + 1);
- memset(cp, 0, strlen (nswp2->orders[0]) + 1);
- strncpy (cp, nswp2->orders[0], strlen(nswp2->orders[0]));
+ strcpy (cp, nswp2->orders[0]);
cmpptr = cp;
nsw_free (nswp2);
}
write_user_data (user_t *data, int is_locked)
{
int retval = 0;
- char err_buf[ERR_BUF_LEN];
if (data->service == S_LOCAL)
{
int gotit, newpf_fd;
char *cp;
- memset(passwd_tmp, 0, strlen (files_etc_dir) + strlen (file_tmp) + 1);
- memset(passwd_orig, 0, strlen (files_etc_dir) + 8);
- memset(passwd_old, 0, strlen (files_etc_dir) + 12);
cp = stpcpy (passwd_tmp, files_etc_dir);
- strncpy (cp, file_tmp, strlen(file_tmp));
+ strcpy (cp, file_tmp);
cp = stpcpy (passwd_orig, files_etc_dir);
- strncpy (cp, "/passwd", strlen("/passwd"));
+ strcpy (cp, "/passwd");
cp = stpcpy (passwd_old, passwd_orig);
- strncpy (cp, ".old", strlen(".old"));
+ strcpy (cp, ".old");
if ((oldpf = fopen (passwd_orig, "r")) == NULL)
{
}
if (fchmod (newpf_fd, passwd_stat.st_mode) < 0)
{
- fprintf (stderr,
- _("Cannot change permissions for `%s': %s\n"),
- passwd_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fprintf (stderr,
+ _("Cannot change permissions for `%s': %s\n"),
+ passwd_tmp, strerror (errno));
fclose (oldpf);
close (newpf_fd);
unlink (passwd_tmp);
goto error_passwd;
}
if (fchown (newpf_fd, passwd_stat.st_uid, passwd_stat.st_gid) < 0)
- {
+ {
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- passwd_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ passwd_tmp, strerror (errno));
fclose (oldpf);
close (newpf_fd);
unlink (passwd_tmp);
int gotit, newpf_fd;
char *cp;
- memset(shadow_tmp, 0, strlen(files_etc_dir) + strlen (file_tmp) + 1);
- memset(shadow_orig, 0, strlen (files_etc_dir) + 8);
- memset(shadow_old, 0 , strlen (files_etc_dir) + 12);
cp = stpcpy (shadow_tmp, files_etc_dir);
- strncpy (cp, file_tmp, strlen(file_tmp));
+ strcpy (cp, file_tmp);
cp = stpcpy (shadow_orig, files_etc_dir);
- strncpy (cp, "/shadow", strlen("/shadow"));
+ strcpy (cp, "/shadow");
cp = stpcpy (shadow_old, shadow_orig);
- strncpy (cp, ".old", strlen(".old"));
+ strcpy (cp, ".old");
/* Open the shadow file for reading. We can't use getspent and
friends here, because they go through the YP maps, too. */
}
if (fchmod (newpf_fd, shadow_stat.st_mode) < 0)
{
- fprintf (stderr,
- _("Cannot change permissions for `%s': %s\n"),
- shadow_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fprintf (stderr,
+ _("Cannot change permissions for `%s': %s\n"),
+ shadow_tmp, strerror (errno));
fclose (oldpf);
close (newpf_fd);
unlink (shadow_tmp);
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- shadow_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ shadow_tmp, strerror (errno));
fclose (oldpf);
close (newpf_fd);
unlink (shadow_tmp);
print_date (time_t date)
{
#ifdef HAVE_STRFTIME
- struct tm *tp, tp_buf;
+ struct tm *tp;
char buf[80];
- tp = gmtime_r (&date, &tp_buf);
+ tp = gmtime (&date);
strftime (buf, sizeof buf, "%b %d, %Y", tp);
puts (buf);
#else
if (!pw_data->use_shadow)
{
char shadowfile[strlen (files_etc_dir) + 8];
- char *cp;
- memset(shadowfile, 0, sizeof(shadowfile));
- cp = stpcpy (shadowfile, files_etc_dir);
- strncpy (cp, "/shadow", strlen("/shadow"));
+ char *cp = stpcpy (shadowfile, files_etc_dir);
+ strcpy (cp, "/shadow");
if (access (shadowfile, F_OK) != 0)
{
if (setgid (getgid ()) || setuid (uid))
{
- char err_buf[ERR_BUF_LEN];
sec_log (program, MSG_DROP_PRIVILEGE_FAILED, errno, uid);
fprintf (stderr, _("%s: Failed to drop privileges: %s\n"),
- program, strerror_r (errno,err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
strlen (new.work_phone) + strlen (new.home_phone) +
strlen (new.other) + 4);
new_gecos = (char *)malloc (len + 1);
- snprintf (new_gecos, len+1, "%s,%s,%s,%s,%s", new.fullname, new.roomno,
+ sprintf (new_gecos, "%s,%s,%s,%s,%s", new.fullname, new.roomno,
new.work_phone, new.home_phone, new.other);
/* remove trailing empty fields (but not subfields of new.other) */
size_t buflen = 0;
unsigned long line = 0, errors = 0;
char *use_service = NULL;
- char err_buf[ERR_BUF_LEN];
#ifdef USE_LDAP
char *oldclearpwd = NULL;
char *binddn = NULL;
if (input == NULL)
{
fprintf (stderr, "%s: %s: %s\n", program, argv[0],
- strerror_r (errno, err_buf, ERR_BUF_LEN));
+ strerror (errno));
return E_BAD_ARG;
}
}
if (force && result == 1)
{
int i;
- char err_buf[ERR_BUF_LEN];
/* close all filehandles. */
for (i = 3; i < getdtablesize(); ++i)
{
sec_log (program, MSG_DROP_PRIVILEGE_FAILED, errno, uid);
fprintf (stderr, _("%s: Failed to drop privileges: %s\n"),
- program, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
int lock_password = 0;
int unlock_password = 0;
char *binddn = NULL;
- //int P_flag = 0;
+ int P_flag = 0;
group_t *gr_data;
char *use_service = NULL;
int stdin_flag = 0;
}
break;
case 'P':
- //P_flag = 1;
+ P_flag = 1;
files_etc_dir = strdup (optarg);
break;
case '\253':
malloc (strlen (gr_data->gr.gr_passwd) + 2);
if (gr_data->newpassword == NULL)
return E_FAILURE;
- memset(gr_data->newpassword, 0, strlen (gr_data->gr.gr_passwd) + 2);
- strncpy (&gr_data->newpassword[1], gr_data->gr.gr_passwd, strlen(gr_data->gr.gr_passwd));
+ strcpy (&gr_data->newpassword[1], gr_data->gr.gr_passwd);
gr_data->newpassword[0] = '!';
}
else
static gid_t
find_free_gid (int is_system_account, int have_extrapath)
{
- struct group *grp, grp_buf;
+ const struct group *grp;
gid_t groupid, gid_min, gid_max;
- char buf[BUF_POOL_LEN];
if (is_system_account)
{
/* Search the entire group file, looking for the
largest unused value. If gid_max does already exists,
skip this. */
- getgrgid_r(gid_max, &grp_buf, buf, BUF_POOL_LEN, &grp);
- if (grp == NULL)
+ if (getgrgid (gid_max) == NULL)
{
setgrent ();
- while (1)
+ while ((grp = getgrent ()))
{
- if(getgrent_r(&grp_buf, buf, BUF_POOL_LEN, &grp) != 0 || grp == NULL)
- {
- break;
- }
if (grp->gr_gid >= groupid)
{
if (grp->gr_gid > gid_max)
if (groupid == gid_max + 1)
{
for (groupid = gid_min; groupid < gid_max; groupid++)
- if (getgrgid_r(groupid, &grp_buf, buf, BUF_POOL_LEN, &grp) != 0 || grp == NULL)
+ if (getgrgid (groupid) == NULL)
{
if (have_extrapath)
{
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
- struct group *grp, grp_buf;
- char buf[BUF_POOL_LEN];
/* Before going any further, raise the ulimit and ignore
signals. */
/* After this, we can start creating the new group. */
if (know_gid && !non_unique)
{
- if ((getgrgid_r(new_gid, &grp_buf, buf, BUF_POOL_LEN, &grp) == 0 && grp != NULL) ||
+ if (getgrgid (new_gid) != NULL ||
(have_extrapath && files_getgrgid (new_gid) != NULL))
{
if (force_add)
sec_log (program, MSG_GROUP_FILE_ALREADY_LOCKED);
return E_PWDBUSY;
}
- else if ((getgrnam_r(new_group, &grp_buf, buf, BUF_POOL_LEN, &grp) == 0 && grp != NULL) ||
+ else if (getgrnam (new_group) != NULL ||
(have_extrapath && files_getgrnam (new_group) != NULL))
{ /* Group does already exists. */
fprintf (stderr, _("%s: Group `%s' already exists.\n"),
static int
is_primary_group (gid_t gid, int have_extrapath)
{
- struct passwd *pw, pw_buf;
+ struct passwd *pw;
int retval = 0;
- char buf[BUF_POOL_LEN];
setpwent ();
- while (1)
- {
- getpwent_r(&pw_buf, buf, BUF_POOL_LEN, &pw);
- if(pw == NULL)
+ while ((pw = getpwent ()))
{
- break;
- }
if (pw->pw_gid == gid)
{
fprintf (stderr,
/* After this, we can start modifying the existing account. */
if (know_gid != NULL && !non_unique)
{
- struct group *grp, grp_buf;
- char buf_pool[BUF_POOL_LEN];
- if ((getgrgid_r(new_gid, &grp_buf, buf_pool, BUF_POOL_LEN, &grp)==0 && grp != NULL) ||
+ if (getgrgid (new_gid) != NULL ||
(have_extrapath && files_getgrgid (new_gid) != NULL))
{
fprintf (stderr, _("%s: GID %u is not unique.\n"),
}
else
{
- struct group *grp, grp_buf;
- char buf_pool[BUF_POOL_LEN];
- if ((getgrnam_r(new_name, &grp_buf, buf_pool, BUF_POOL_LEN, &grp) == 0 && grp != NULL) ||
+ if (getgrnam (new_name) != NULL ||
(have_extrapath && files_getgrnam (new_name) != NULL))
{
fprintf (stderr, _("%s: Group `%s' already exists.\n"),
exit (E_FAILURE);
}
- memset(inputname, 0, strlen (files_etc_dir) + 8);
- memset(outputname, 0, strlen (files_etc_dir) + 20);
- strncpy(inputname, files_etc_dir, strlen(files_etc_dir));
- strncat (inputname, "/group", strlen("/group"));
- strncpy (outputname, files_etc_dir, strlen(files_etc_dir));
- strncat (outputname, "/group.tmpXXXXXX", strlen("/group.tmpXXXXXX"));
+ strcpy (inputname, files_etc_dir);
+ strcat (inputname, "/group");
+ strcpy (outputname, files_etc_dir);
+ strcat (outputname, "/group.tmpXXXXXX");
if (!quiet)
printf (_("Checking `%s'\n"), inputname);
if (input == NULL)
{
fprintf (stderr, _("Can't open `%s': %m\n"), inputname);
- free(buffer);
return E_NO_FILE;
}
{
fprintf (stderr, _("Can't stat `%s': %m\n"), inputname);
fclose (input);
- free(buffer);
return E_NO_FILE;
}
if (set_default_context (inputname, &prev_context) < 0)
{
fclose (input);
- free(buffer);
return E_NO_FILE;
}
#endif
if (output_fd >= 0)
close (output_fd);
fclose (input);
- free(buffer);
return E_FAILURE;
}
#endif
fprintf (stderr, _("Can't create `%s': %m\n"),
inputname);
fclose (input);
- free(buffer);
return E_NO_FILE;
}
if (fchmod (output_fd, group_stat.st_mode) < 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr,
_("Cannot change permissions for `%s': %s\n"),
- outputname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ outputname, strerror (errno));
fclose (input);
close (output_fd);
unlink (outputname);
- free(buffer);
return E_NO_FILE;
}
if (fchown (output_fd, group_stat.st_uid, group_stat.st_gid) < 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- outputname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ outputname, strerror (errno));
fclose (input);
close (output_fd);
unlink (outputname);
- free(buffer);
return E_NO_FILE;
}
if (copy_xattr (inputname, outputname) != 0)
fclose (input);
close (output_fd);
unlink (outputname);
- free(buffer);
return E_NO_FILE;
}
output = fdopen (output_fd, "w+");
fclose (input);
close (output_fd);
unlink (outputname);
- free(buffer);
return E_NO_FILE;
}
group of the member. */
for (i = 0; res.gr_mem[i]; i++)
{
- struct passwd *pw, pw_buf;
- char buf_pw[BUF_PW_LEN];
+ struct passwd *pw;
- getpwnam_r(res.gr_mem[i], &pw_buf, buf_pw, BUF_PW_LEN, &pw);
+ pw = getpwnam (res.gr_mem[i]);
if (pw == NULL)
pw = files_getpwnam (res.gr_mem[i]);
if (modified)
{
char *oldname = alloca (strlen (files_etc_dir) + 20);
- memset(oldname, 0, strlen (files_etc_dir) + 20);
- strncpy (oldname, files_etc_dir, strlen(files_etc_dir));
- strncat (oldname, "/group.old", strlen("/group.old"));
+ strcpy (oldname, files_etc_dir);
+ strcat (oldname, "/group.old");
unlink (oldname);
if (link (inputname, oldname) < 0)
fprintf (stderr,
int newgf_fd;
char *cp;
- memset(group_tmp, 0, strlen (files_etc_dir) + strlen (file_tmp) + 1);
- memset(group_orig, 0, strlen (files_etc_dir) + 8);
- memset(group_old, 0, strlen (files_etc_dir) + 12);
cp = stpcpy (group_tmp, files_etc_dir);
- strncpy(cp, file_tmp, strlen(file_tmp));
+ strcpy (cp, file_tmp);
cp = stpcpy (group_orig, files_etc_dir);
- strncpy (cp, "/group", strlen("/group"));
+ strcpy (cp, "/group");
cp = stpcpy (group_old, group_orig);
- strncpy (cp, ".old", strlen(".old"));
+ strcpy (cp, ".old");
if ((oldgf = fopen (group_orig, "r")) == NULL)
{
}
if (fchmod (newgf_fd, group_stat.st_mode) < 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr,
_("Cannot change permissions for `%s': %s\n"),
- group_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ group_tmp, strerror (errno));
fclose (oldgf);
close (newgf_fd);
unlink (group_tmp);
}
if (fchown (newgf_fd, group_stat.st_uid, group_stat.st_gid) < 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- group_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ group_tmp, strerror (errno));
fclose (oldgf);
close (newgf_fd);
unlink (group_tmp);
setsgent (void)
{
char *filename = alloca (strlen (files_etc_dir) + 10);
- memset(filename, 0, strlen (files_etc_dir) + 10);
- strncpy (filename, files_etc_dir, strlen(files_etc_dir));
- strncat (filename, "/gshadow", strlen("/gshadow"));
+ strcpy (filename, files_etc_dir);
+ strcat (filename, "/gshadow");
sg_stream = fopen (filename, "r");
int
main (int argc, char *argv[])
{
- struct passwd *pw, pw_buf;
- char buf_pw[BUF_PW_LEN];
+ struct passwd *pw;
char *program;
char *cp, *shell;
char *c_flag = NULL;
return E_USAGE;
}
- if (getpwuid_r(getuid(), &pw_buf, buf_pw, BUF_PW_LEN, &pw) != 0 || pw == NULL)
+ if ((pw = getpwuid (getuid())) == NULL)
{
fprintf (stderr, _("%s: Unknown user.\n"), program);
exit (E_FAILURE);
if (argc == 1) /* Change primary group to new one. */
{
- struct group *grp, grp_buf;
- char buf_pool[BUF_POOL_LEN];
+ struct group *grp;
gid_t gid;
- //gid_t egid;
+ gid_t egid;
int is_member = 0;
int ngroups, ngroups_allocated, i;
gid_t *grouplist;
char *utf8_arg = locale_to_utf8 (argv[0]);
/* Try it as a group name, then a group id. */
- if ((getgrnam_r(utf8_arg, &grp_buf, buf_pool, BUF_POOL_LEN, &grp) != 0 || grp == NULL) &&
+ if ((grp = getgrnam (utf8_arg)) == NULL &&
(strtoid (utf8_arg, &gid) == -1 ||
- (getgrgid_r(gid, &grp_buf, buf_pool, BUF_POOL_LEN, &grp) != 0 || grp == NULL)))
+ (grp = getgrgid (gid)) == NULL))
{
fprintf (stderr, _("%s: bad group `%s'.\n"), program, argv[0]);
return E_USAGE;
}
if ((count = getgroups(count, groupIDs)) < 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("%s: calling getgroups failed: %s\n"),
- program, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
for (i = 0; i < count; i++ )
/* check in databases if not already found */
if (!is_member)
{
- struct group *g, g_buf;
+ struct group *g;
char **gp;
gid_t search_gid;
- char buf_pool[BUF_POOL_LEN];
/* grp will be no longer valid after setgrent() call. */
search_gid = grp->gr_gid;
to step through all group entries and search for the correct
one. */
setgrent ();
- while (!is_member && (getgrent_r(&g_buf, buf_pool, BUF_POOL_LEN, &g) == 0 && g != NULL))
+ while (!is_member && (g = getgrent ()) != NULL)
{
if (g->gr_gid != search_gid)
continue;
/* endgrent (); */ /* Don't invalidate grp pointer. */
if (grp == NULL)
{ /* restore grp pointer, user is no member. */
- if (getgrgid_r(gid, &grp_buf, buf_pool, BUF_POOL_LEN, &grp) != 0 || grp == NULL )
+ if ((grp = getgrgid (search_gid)) == NULL)
{
fprintf (stderr,
_("%s: failure to get group entry for %d.\n"),
}
}
- //egid = getegid();
+ egid = getegid();
/* Find out, how many sumplementary groups exists and allocate
enough memory for one additional group. */
if ((ngroups = getgroups (ngroups, grouplist)) < 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("%s: calling getgroups failed: %s\n"),
- program, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
if (setgroups (ngroups, (grouplist)) < 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("%s: calling setgroups failed: %s\n"),
- program, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
if (setgid (grp->gr_gid) < 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("%s: calling setgid failed: %s\n"),
- program, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
}
{
if (initgroups (pw->pw_name, pw->pw_gid) != 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("%s: calling initgroups failed: %s\n"),
- program, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
if (setgid (pw->pw_gid) != 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("%s: calling setgid failed: %s\n"),
- program, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
}
/* Drop root privilegs. */
if (setuid (getuid ()) != 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("%s: calling setuid failed: %s\n"),
- program, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
return E_FAILURE;
}
if (chdir (pw->pw_dir) != 0)
{
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("Cannot change to directory %s: %s\n"),
- pw->pw_dir, strerror_r(errno, err_buf, ERR_BUF_LEN));
+ pw->pw_dir, strerror (errno));
if (!getlogindefs_bool ("DEFAULT_HOME", 1))
return E_FAILURE;
if (chdir ("/") < 0)
execl (shell, basename (shell), NULL);
/* execv or execl failed. */
- {
- char err_buf[ERR_BUF_LEN];
fprintf (stderr, _("%s: execl failed: %s\n"),
- program, strerror_r(errno, err_buf, ERR_BUF_LEN));
- }
+ program, strerror (errno));
/* should never be reached! */
return E_FAILURE;
date_to_str (time_t t)
{
static char buf[80];
- struct tm *tm, tm_buf;
+ struct tm *tm;
- tm = gmtime_r(&t, &tm_buf);
+ tm = gmtime (&t);
strftime (buf, sizeof buf, "%m/%d/%Y", tm);
return buf;
}
char *buffer = alloca (buflen);
struct passwd resultbuf;
struct passwd *pw = NULL;
- char buf_pw[BUF_PW_LEN];
int admin_only = 0;
int silent = 0;
uid_t uid = getuid ();
}
sec_log (program, MSG_DISPLAY_PASSWORD_STATUS_FOR_ALL, uid);
setpwent ();
- while (getpwent_r(&resultbuf, buf_pw, BUF_PW_LEN, &pw) == 0 && pw != NULL)
+ while ((pw = getpwent ()))
display_pw (pw);
endpwent ();
return E_SUCCESS;
pw_data->newpassword = malloc (strlen (pwdp) + 2);
if (pw_data->newpassword == NULL)
return E_FAILURE;
- memset(pw_data->newpassword, 0, strlen (pwdp) + 2);
- strncpy (&pw_data->newpassword[1], pwdp, strlen(pwdp));
+ strcpy (&pw_data->newpassword[1], pwdp);
pw_data->newpassword[0] = '!';
}
else
if (setuid (getuid ()) != 0)
{
- char err_buf[ERR_BUF_LEN];
sec_log (prog, MSG_DROP_PRIVILEGE_FAILED, errno, getuid());
fprintf (stderr, _("%s: Failed to drop privileges: %s\n"),
- prog, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ prog, strerror (errno));
return E_FAILURE;
}
switch (argv[1][1])
int modified = 0;
char *inputname = alloca (strlen (files_etc_dir) + 8);
char *outputname = alloca (strlen (files_etc_dir) + 20);
- struct group grp, *grpresult;
- char grpBuffer[BUF_POOL_LEN];
- char err_buf[ERR_BUF_LEN];
- memset( inputname, 0, strlen (files_etc_dir) + 8);
- memset( outputname, 0, strlen (files_etc_dir) + 20);
- strncpy (inputname, files_etc_dir, strlen(files_etc_dir));
- strncat (inputname, "/passwd", strlen("/passwd"));
- strncpy (outputname, files_etc_dir, strlen(files_etc_dir));
- strncat (outputname, "/passwd.tmpXXXXXX", strlen("/passwd.tmpXXXXXX"));
+ strcpy (inputname, files_etc_dir);
+ strcat (inputname, "/passwd");
+ strcpy (outputname, files_etc_dir);
+ strcat (outputname, "/passwd.tmpXXXXXX");
if (!quiet)
printf (_("Checking `%s'\n"), inputname);
if (fchmod (output_fd, passwd_stat.st_mode) < 0)
{
fprintf (stderr,
- _("Cannot change permissions for `%s': %s\n"),
- outputname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ _("Cannot change permissions for `%s': %s\n"),
+ outputname, strerror (errno));
fclose (input);
close (output_fd);
unlink (outputname);
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- outputname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ outputname, strerror (errno));
fclose (input);
close (output_fd);
unlink (outputname);
blacklist_store_name (res.pw_name, &blacklist);
/* Check, if primary group exists. */
- getgrgid_r (res.pw_gid, &grp, grpBuffer, BUF_POOL_LEN, &grpresult);
- if(!quiet && grpresult == NULL &&
- files_getgrgid (res.pw_gid) == NULL)
+ if (!quiet && getgrgid (res.pw_gid) == NULL &&
+ files_getgrgid (res.pw_gid) == NULL)
{
result = E_BAD_ENTRY;
printf (_("User `%s': unknown group `%u'\n"),
if (modified)
{
char *oldname = alloca (strlen (files_etc_dir) + 20);
- memset( oldname, 0, strlen (files_etc_dir) + 20);
- strncpy (oldname, files_etc_dir, strlen(files_etc_dir));
- strncat (oldname, "/passwd.old", strlen("/passwd.old"));
+ strcpy (oldname, files_etc_dir);
+ strcat (oldname, "/passwd.old");
unlink (oldname);
if (link (inputname, oldname) < 0)
fprintf (stderr,
int modified = 0;
char *inputname = alloca (strlen (files_etc_dir) + 8);
char *outputname = alloca (strlen (files_etc_dir) + 20);
- char err_buf[ERR_BUF_LEN];
-
- memset( inputname, 0, strlen (files_etc_dir) + 8);
- memset( outputname, 0, strlen (files_etc_dir) + 20);
- strncpy (inputname, files_etc_dir, strlen(files_etc_dir));
- strncat (inputname, "/shadow", strlen("/shadow"));
- strncpy (outputname, files_etc_dir, strlen(files_etc_dir));
- strncat (outputname, "/shadow.tmpXXXXXX", strlen("/shadow.tmpXXXXXX"));
+
+ strcpy (inputname, files_etc_dir);
+ strcat (inputname, "/shadow");
+ strcpy (outputname, files_etc_dir);
+ strcat (outputname, "/shadow.tmpXXXXXX");
input = fopen (inputname, "r");
if (input == NULL)
{
fprintf (stderr,
_("Cannot change permissions for `%s': %s\n"),
- outputname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ outputname, strerror (errno));
fclose (input);
close (output_fd);
unlink (outputname);
if (fchown (output_fd, shadow_stat.st_uid, shadow_stat.st_gid) < 0)
{
fprintf (stderr,
- _("Cannot change owner/group for `%s': %s\n"),
- outputname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ _("Cannot change owner/group for `%s': %s\n"),
+ outputname, strerror (errno));
fclose (input);
close (output_fd);
unlink (outputname);
if (modified)
{
char *oldname = alloca (strlen (files_etc_dir) + 20);
- memset( oldname, 0, strlen (files_etc_dir) + 20);
- strncpy (oldname, files_etc_dir, strlen(files_etc_dir));
- strncat (oldname, "/shadow.old", strlen("/shadow.old"));
+ strcpy (oldname, files_etc_dir);
+ strcat (oldname, "/shadow.old");
unlink (oldname);
if (link (inputname, oldname) < 0)
fprintf (stderr,
struct passwd *pwd;
struct passwd_list *ptr = NULL;
int retval = 0;
- char err_buf[ERR_BUF_LEN];
while ((pwd = files_getpwent ()))
{
int newgf_fd;
char *cp;
- memset( passwd_tmp, 0, strlen (files_etc_dir) + strlen (file_tmp) + 1);
+
cp = stpcpy (passwd_tmp, files_etc_dir);
- strncpy (cp, file_tmp, strlen(file_tmp));
- memset(passwd_orig, 0 , strlen (files_etc_dir) + 8);
+ strcpy (cp, file_tmp);
cp = stpcpy (passwd_orig, files_etc_dir);
- strncpy (cp, "/passwd", strlen("/passwd"));
- memset(passwd_old, 0 , strlen (files_etc_dir) + 12);
+ strcpy (cp, "/passwd");
cp = stpcpy (passwd_old, passwd_orig);
- strncpy (cp, ".old", strlen(".old"));
+ strcpy (cp, ".old");
if ((oldgf = fopen (passwd_orig, "r")) == NULL)
{
if (fchmod (newgf_fd, passwd_stat.st_mode) < 0)
{
fprintf (stderr,
- _("Cannot change permissions for `%s': %s\n"),
- passwd_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ _("Cannot change permissions for `%s': %s\n"),
+ passwd_tmp, strerror (errno));
fclose (oldgf);
close (newgf_fd);
unlink (passwd_tmp);
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- passwd_tmp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ passwd_tmp, strerror (errno));
fclose (oldgf);
close (newgf_fd);
unlink (passwd_tmp);
char *cp;
char *tmpshadow = NULL;
char *tmppasswd = NULL;
- char buffer[BUF_POOL_LEN];
- struct group resultbuf, *shadow_grp;
- char err_buf[ERR_BUF_LEN];
+
+
#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
if (errno == ENOENT)
{
int fd = creat (path, S_IRUSR|S_IWUSR);
- getgrnam_r ("shadow", &resultbuf, buffer, BUF_POOL_LEN, &shadow_grp);
+ struct group *shadow_grp = getgrnam ("shadow");
if (fd < 0)
{
if (chown (path, 0, shadow_grp ? shadow_grp->gr_gid : 0) < 0)
{
- fprintf (stderr,
- _("Cannot change owner/group for `%s': %s\n"),
- path, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fprintf (stderr,
+ _("Cannot change owner/group for `%s': %s\n"),
+ path, strerror (errno));
unlink (path);
free (path);
return E_FAILURE;
{
fprintf (stderr,
_("Cannot change permissions for `%s': %s\n"),
- path, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ path, strerror (errno));
unlink (path);
free (path);
return E_FAILURE;
#include <slp.h>
#endif
-#define ERR_BUF_LEN 256
-#define BUF_POOL_LEN 16384
#ifdef USE_GNUTLS
static int
struct addrinfo hints, *res, *res0;
int error;
int sock = -1;
- char err_buf[ERR_BUF_LEN];
memset (&hints, 0, sizeof (hints));
hints.ai_family = family;
if (getnameinfo (res->ai_addr, res->ai_addrlen,
hbuf, sizeof (hbuf), NULL, 0, niflags) != 0)
- {
- memset( hbuf, 0, strlen(hbuf));
- strncpy (hbuf, "(invalid)", strlen("(invalid)"));
- }
+ strcpy (hbuf, "(invalid)");
switch (res->ai_family)
{
case AF_INET:
{
if (getnameinfo (res->ai_addr, res->ai_addrlen,
hbuf, sizeof (hbuf), NULL, 0, niflags) != 0)
- {
- memset( hbuf, 0, strlen(hbuf));
- strncpy (hbuf, "(invalid)", strlen("(invalid)"));
- }
+ strcpy (hbuf, "(invalid)");
PRINTF (ERR_HANDLE, _("connect to address %s: %s\n"), hbuf,
- strerror_r (errno, err_buf, ERR_BUF_LEN));
+ strerror (errno));
close (sock);
sock = -1;
continue;
DIR *dir = opendir ("/etc/ssl/certs");
struct dirent *entry;
int ret;
+
/* Allow connections to servers that have OpenPGP keys as well. */
const int cert_type_priority[3] =
{ GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0 };
struct stat st;
char *cp;
- memset( srcfile, 0, sizeof(srcfile));
/* create source and destination filename with full path. */
cp = stpcpy (srcfile, "/etc/ssl/certs");
*cp++ = '/';
- strncpy (cp, entry->d_name, strlen(entry->d_name));
+ strcpy (cp, entry->d_name);
if (lstat (srcfile, &st) != 0)
continue;
#define IPV6_V6ONLY 26
#endif
-#define ERR_BUF_LEN 256
-#define BUF_POOL_LEN 16384
-
/* Path of the file where the PID of the running system is stored. */
#define _PATH_RPASSWDDPID "/var/run/rpasswdd.pid"
fprintf (fp, "%d\n", getpid ());
if (fflush (fp) || ferror (fp))
- {
- fclose (fp);
return -1;
- }
fclose (fp);
server_init (int port, int ipv4, int ipv6)
{
int have_usagi = 1; /* Assume we have a USAGI patched kernel. */
- char err_buf[ERR_BUF_LEN];
/* The Linux kernel without USAGI patch will handle IPv4 connections
over an existing IPv6 binding. So we cannot bind explicit a IPv6
pollfd_conn[pollfd_cnt].fd = socket (AF_INET6, SOCK_STREAM, 0);
if (pollfd_conn[pollfd_cnt].fd < 0)
{
- dbg_log ("cannot open socket: %s", strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dbg_log ("cannot open socket: %s", strerror (errno));
exit (1);
}
if (bind (pollfd_conn[pollfd_cnt].fd, (struct sockaddr *) &sock_addr,
sizeof (sock_addr)) < 0)
{
- dbg_log ("bind: %s", strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dbg_log ("bind: %s", strerror (errno));
exit (1);
}
if (listen (pollfd_conn[pollfd_cnt].fd, SOMAXCONN) < 0)
{
dbg_log ("cannot enable socket to accept connections: %s",
- strerror_r (errno, err_buf, ERR_BUF_LEN));
+ strerror (errno));
exit (1);
}
++pollfd_cnt;
pollfd_conn[pollfd_cnt].fd = socket (AF_INET, SOCK_STREAM, 0);
if (pollfd_conn[pollfd_cnt].fd < 0)
{
- dbg_log ("cannot open socket: %s", strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dbg_log ("cannot open socket: %s", strerror (errno));
exit (1);
}
if (bind (pollfd_conn[pollfd_cnt].fd, (struct sockaddr *) &sock_addr,
sizeof (sock_addr)) < 0)
{
- dbg_log ("bind: %s", strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dbg_log ("bind: %s", strerror (errno));
exit (1);
}
if (listen (pollfd_conn[pollfd_cnt].fd, SOMAXCONN) < 0)
{
dbg_log ("cannot enable socket to accept connections: %s",
- strerror_r (errno, err_buf, ERR_BUF_LEN));
+ strerror (errno));
exit (1);
}
++pollfd_cnt;
/* Don't print error messages if poll is only interupted
by a signal. */
if (errno != EINTR)
- dbg_log ("poll() failed: %s", strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dbg_log ("poll() failed: %s", strerror (errno));
continue;
}
else if (nr == 0)
safe_read (SSL *ssl, void *data, size_t count, int timeout)
{
struct pollfd conn;
- char err_buf[ERR_BUF_LEN];
+
conn.fd = SSL_get_fd (ssl);
conn.events = POLLRDNORM;
/* Don't print error messages if poll is only interupted
by a signal. */
if (errno != EINTR)
- dbg_log ("poll() failed: %s", strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dbg_log ("poll() failed: %s", strerror (errno));
continue;
}
else if (nr == 0)
char *pw_buffer = alloca (pw_buflen);
struct passwd pw_resultbuf;
struct passwd *pw = NULL;
- char err_buf[ERR_BUF_LEN];
if (debug_level > 0)
dbg_log ("handle_request: request received (Version = %d)",
root. With this, most PAM modules thinks they are called from
a setuid root passwd program. Not needed if we run in Admin mode.
In this case, PAM moduls should think passwd is called by root. */
- if (pw != NULL && setresuid (pw->pw_uid, 0, 0) == -1)
- {
- char *cp;
+ if (setresuid (pw->pw_uid, 0, 0) == -1)
+ {
+ char *cp;
if (asprintf (&cp, _("setresuid failed on server: %s"),
- strerror_r (errno, err_buf, ERR_BUF_LEN)) > 0)
+ strerror (errno)) > 0)
{
dbg_log (cp);
send_string (ssl, ERROR_MSG, cp);
#endif
{
int i;
- char err_buf[ERR_BUF_LEN];
for (i = 0; i < pollfd_cnt; i++)
pollfd_conn[i].events = POLLRDNORM;
/* Don't print error messages if poll is only interupted
by a signal. */
if (errno != EINTR)
- dbg_log ("poll() failed: %s", strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dbg_log ("poll() failed: %s", strerror (errno));
continue;
}
{
if (debug_level > 0)
{
+ char err_buf[256];
+
if (errno == 0)
dbg_log ("error while reading request locale: %s",
"wrong data received");
{
if (debug_level > 0)
{
+ char err_buf[256];
+
if (errno == 0)
dbg_log ("error while reading request username: %s",
"wrong data received");
{
char *cp;
- if (asprintf (&cp, "fork: %s", strerror_r (errno, err_buf, ERR_BUF_LEN)) > 0)
+ if (asprintf (&cp, "fork: %s", strerror (errno)) > 0)
{
dbg_log (cp);
send_string (ssl, ERROR_MSG, cp);
int slp_timeout = 3600;
char *slp_descr = NULL;
#endif
- struct servent *serv, res;
- char buffer[BUF_POOL_LEN];
- char err_buf[ERR_BUF_LEN];
#ifndef USE_GNUTLS
SSL_METHOD *meth;
#endif
setsid ();
- if (chdir ("/") < 0)
- dbg_log ("chdir(\"/\") failed: %s", strerror_r (errno, err_buf, ERR_BUF_LEN));
+ if (chdir ("/") < 0)
+ dbg_log ("chdir(\"/\") failed: %s", strerror (errno));
openlog (program, LOG_CONS | LOG_ODELAY, LOG_DAEMON);
if (write_pid (_PATH_RPASSWDDPID) < 0)
- dbg_log ("%s: %s", _PATH_RPASSWDDPID, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ dbg_log ("%s: %s", _PATH_RPASSWDDPID, strerror (errno));
/* Ignore job control signals. */
signal (SIGTTOU, SIG_IGN);
default port. */
if (port == -1)
{
- getservbyname_r("rpasswd", "tcp", &res, buffer, sizeof(buffer), &serv);
+ struct servent *serv = getservbyname ("rpasswd", "tcp");
if (serv)
port = serv->s_port;
char *buf = NULL;
size_t buflen = 0;
int errors = 0;
- char buffer[BUF_POOL_LEN];
- struct group resultbuf;
fp = fopen (configfile, "r");
if (NULL == fp)
if (cp[6] != '\0' && strtoid (&cp[6], &grpid) == 0)
/* GID in numeric form */
data->group = grpid;
- else if (getgrnam_r (&cp[6], &resultbuf, buffer, BUF_POOL_LEN, &grp) == 0 && grp != NULL)
+ else if ((grp = getgrnam (&cp[6])) != NULL)
data->group = grp->gr_gid;
else
{
int group_written = 0, home_written = 0, inactive_written = 0;
int expire_written = 0, shell_written = 0, groups_written = 0;
int skel_written = 0, create_mail_spool_written = 0, umask_written = 0;
- char err_buf[ERR_BUF_LEN];
fp = fopen (configfile, "r");
if (NULL == fp)
return -1;
- memset(tmpname, 0, sizeof(tmpname));
cp = stpcpy (tmpname, configfile);
- strncpy (cp, tmpsuffix, strlen(tmpsuffix));
+ strcpy (cp, tmpsuffix);
if (fstat (fileno (fp), &oldmode) < 0)
{
}
if (fchmod (new_fd, oldmode.st_mode) < 0)
{
- fprintf (stderr,
- _("Cannot change permissions for `%s': %s\n"),
- tmpname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fprintf (stderr,
+ _("Cannot change permissions for `%s': %s\n"),
+ tmpname, strerror (errno));
fclose (fp);
close (new_fd);
unlink (tmpname);
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- tmpname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ tmpname, strerror (errno));
fclose (fp);
close (new_fd);
unlink (tmpname);
static uid_t
find_free_uid (int is_system_account, int have_extrapath)
{
- struct passwd *pwd, pwd_buf;
- uid_t userid, uid_min, uid_max;
- char buf_pool[BUF_POOL_LEN];
+ const struct passwd *pwd;
+ uid_t userid, uid_min, uid_max;
if (is_system_account)
{
/* Search the entire password file, looking for the
largest unused value. If uid_max does already exists,
skip this. */
- if (getpwuid_r (uid_max, &pwd_buf, buf_pool, BUF_POOL_LEN, &pwd) != 0 || pwd == NULL)
+ if (getpwuid (uid_max) == NULL)
{
setpwent ();
- while(1)
+ while ((pwd = getpwent ()))
{
- getpwent_r(&pwd_buf, buf_pool, BUF_POOL_LEN, &pwd);
- if(pwd == NULL) break;
if (pwd->pw_uid >= userid)
{
if (pwd->pw_uid > uid_max)
if (userid == uid_max + 1)
{
for (userid = uid_min; userid < uid_max; userid++)
- if (getpwuid_r (userid, &pwd_buf, buf_pool, BUF_POOL_LEN, &pwd) != 0 || pwd == NULL)
+ if (getpwuid (userid) == NULL)
{
if (have_extrapath)
{
char *fname;
struct stat st;
char *cp;
- char err_buf[ERR_BUF_LEN];
if ((fname = malloc (strlen (user) +
strlen (_PATH_MAILDIR) + 2)) == NULL)
fputs ("running out of memory!\n", stderr);
return E_MAIL_SPOOL;
}
- memset( fname, 0, strlen (user) + strlen (_PATH_MAILDIR) + 2);
cp = stpcpy (fname, _PATH_MAILDIR);
*cp++ = '/';
- strncpy (cp, user, strlen(user));
+ strcpy (cp, user);
if (access (fname, R_OK) == 0)
- {
- free (fname);
return 0;
- }
if (stat (_PATH_MAILDIR, &st) == -1)
{
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- fname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fname, strerror (errno));
unlink (fname);
free (fname);
close (fd);
{
fprintf (stderr,
_("Cannot change permissions for `%s': %s\n"),
- fname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fname, strerror (errno));
unlink (fname);
free (fname);
close (fd);
const char *skeldir, int home_umask)
{
int retval = 0;
- char *lasts = NULL;
- char err_buf[ERR_BUF_LEN];
if (home == NULL || *home == '\0')
return E_HOMEDIR;
/* Check for every part of the path, if the directory
exists. If not, create it with permissions 755 and
owner root:root. */
- cp = strtok_r (bhome, "/", &lasts);
- memset( path, 0, sizeof(path));
+ cp = strtok (bhome, "/");
while (cp)
{
- strncat (path, "/", strlen("/"));
- strncat (path, cp, strlen(cp));
+ strcat (path, "/");
+ strcat (path, cp);
if (access (path, F_OK) != 0)
{
if (mkdir (path, 0) != 0)
fprintf (stderr, _("%s: Warning: chmod on `%s' failed: %m\n"),
program, path);
}
- cp = strtok_r (NULL, "/", &lasts);
+ cp = strtok (NULL, "/");
}
if (chown (home, uid, gid) < 0)
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- home, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ home, strerror (errno));
retval = E_HOMEDIR;
}
if (chmod (home, 0777 & ~home_umask) < 0)
{
fprintf (stderr, _("Cannot change permissions for `%s': %s\n"),
- home, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ home, strerror (errno));
retval = E_HOMEDIR;
}
int create_homedir = 0;
int modify_defaults = 0;
int broken_default_useradd = 0;
- char buf_pool[BUF_POOL_LEN];
- struct passwd *pwd, pwd_buf;
- char err_buf[ERR_BUF_LEN];
+
#ifdef ENABLE_NLS
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
char *buffer = alloca (buflen);
struct passwd resultbuf;
struct passwd *pw;
-
+
/* Determine our own user name for PAM authentication. */
while (getpwuid_r (getuid (), &resultbuf, buffer, buflen, &pw) != 0
&& errno == ERANGE)
/* After this, we can start creating the new account. */
if (know_uid && !non_unique)
{
- if ((getpwuid_r (new_uid, &pwd_buf, buf_pool, BUF_POOL_LEN, &pwd) == 0 && pwd != NULL)||
+ if (getpwuid (new_uid) != NULL ||
(have_extrapath && files_getpwuid (new_uid) != NULL))
{
if(prefer_uid)
fputs (_("Cannot lock password file: already locked.\n"), stderr);
return E_PWDBUSY;
}
- else if ((getpwnam_r (new_account, &pwd_buf, buf_pool, BUF_POOL_LEN, &pwd) == 0 && pwd != NULL)||
+ else if (getpwnam (new_account) != NULL ||
(have_extrapath && files_getpwnam (new_account) != NULL))
{ /* User does already exists. */
sec_log (program, MSG_USER_ALREADY_EXISTS, new_account, getuid ());
memset (&pw_data, 0, sizeof (pw_data));
/* check if we have shadow support. */
- memset(shadowfile, 0, sizeof(shadowfile));
cp = stpcpy (shadowfile, files_etc_dir);
- strncpy (cp, "/shadow", strlen("/shadow"));
+ strcpy (cp, "/shadow");
pw_data.use_shadow = (access (shadowfile, F_OK) == 0);
if (use_service)
{
/* Clear old log entries, but only if this UID is not shared
with another account. */
- if ((getpwuid_r (pw_data.pw.pw_uid, &pwd_buf, buf_pool, BUF_POOL_LEN, &pwd) != 0 || pwd == NULL) &&
+ if (getpwuid (pw_data.pw.pw_uid) == NULL &&
(!have_extrapath || files_getpwuid (pw_data.pw.pw_uid) == NULL))
{
int fd;
== (off_t)-1) || (write (fd, &fl, sizeof (fl)) == -1))
fprintf (stderr,
_("%s: Error: Cannot clear old faillog entry: %s\n"),
- program, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
close (fd);
}
== (off_t)-1) || (write (fd, &ll, sizeof (ll)) == -1))
fprintf (stderr,
_("%s: Error: Cannot clear old lastlog entry: %s\n"),
- program, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ program, strerror (errno));
close (fd);
}
}
struct passwd *pw;
size_t dirlen = strlen (dir);
int retval = 0;
- struct passwd pwp;
- char buf[BUF_POOL_LEN];
setpwent ();
- while(1)
- {
- getpwent_r(&pwp, buf, BUF_POOL_LEN, &pw);
- if(pw == NULL) break;
+
+ while ((pw = getpwent ()))
+ {
/* don't count ourself. */
if (strcmp (pw->pw_name, user) == 0)
continue;
} *list = NULL, *item;
struct group *gr;
int retval = E_SUCCESS;
- struct group grp;
- char buf[BUF_POOL_LEN];
if (have_extrapath)
{
}
else
{
- setgrent ();
-
- while(1)
- {
- getgrent_r(&grp, buf, BUF_POOL_LEN, &gr);
- if(gr == NULL) break;
+ setgrent ();
+
+ while ((gr = getgrent ()))
+ {
unsigned int i;
for (i = 0; gr->gr_mem[i]; i++)
user_t *pw_data;
int retval = E_SUCCESS;
int i;
- char err_buf[ERR_BUF_LEN];
#ifdef ENABLE_NLS
setlocale (LC_ALL, "");
}
else if (ret == 1 || (ret == 0 && force_removal))
{
- if (unlink (cp) == -1)
+ if (unlink (cp) == -1)
fprintf (stderr, _("%s: warning: can't remove `%s': %s"),
- program, cp, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ program, cp, strerror (errno));
}
/* Remove the home directory only, if owned by the user and
{
if (remove_dir_rec (pw_data->pw.pw_dir) != 0)
fprintf (stderr, _("%s: warning: can't remove `%s': %s"),
- program, pw_data->pw.pw_dir, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ program, pw_data->pw.pw_dir, strerror (errno));
else
{
sec_log (program, MSG_HOME_DIR_REMOVED,
} *list = NULL, *item;
struct group *gr;
int retval = E_SUCCESS;
- struct group grp;
- char buf[BUF_POOL_LEN];
if (have_extrapath)
{
}
else
{
- setgrent ();
-
- while(1)
- {
- getgrent_r(&grp, buf, BUF_POOL_LEN, &gr);
- if(gr == NULL) break;
+ setgrent ();
+
+ while ((gr = getgrent ()))
+ {
unsigned int i;
for (i = 0; gr->gr_mem[i]; i++)
move_home_directory (const char *oldhome, const char *newhome)
{
struct stat st;
- char *lasts = NULL;
if (oldhome == NULL || *oldhome == '\0' ||
newhome == NULL || *newhome == '\0')
/* Check for every part of the path, if the directory
exists. If not, create it with permissions 755 and
owner root:root. */
- cp = strtok_r(bhome, "/", &lasts);
- memset( path, 0, sizeof(path));
+ cp = strtok (bhome, "/");
while (cp)
{
- strncat (path, "/", strlen("/"));
- strncat (path, cp, strlen(cp));
+ strcat (path, "/");
+ strcat (path, cp);
if (access (path, F_OK) != 0)
{
if (mkdir (path, 0) != 0)
fprintf (stderr, _("%s: Warning: chmod on `%s' failed: %m\n"),
program, path);
}
- cp = strtok_r(NULL, "/", &lasts);
+ cp = strtok (NULL, "/");
}
/* we have this created to much, remove it again. */
rmdir (newhome);
} *list = NULL, *item;
struct group *gr;
int retval = E_SUCCESS;
- struct group grp;
- char buf[BUF_POOL_LEN];
if (have_extrapath)
{
}
else
{
- setgrent ();
+ setgrent ();
- while(1)
- {
- getgrent_r(&grp, buf, BUF_POOL_LEN, &gr);
- if(gr == NULL) break;
+ while ((gr = getgrent ()))
+ {
unsigned int i;
for (i = 0; gr->gr_mem[i]; i++)
{
char *editor;
pid_t pid;
- char err_buf[ERR_BUF_LEN];
if ((editor = getenv("EDITOR")) == NULL)
editor = strdup(_PATH_VI);
pid = fork();
if (pid < 0) /* Error */
{
- fprintf (stderr, _("Cannot fork: %s\n"),
- strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fprintf (stderr, _("Cannot fork: %s\n"), strerror (errno));
return E_FAILURE;
}
else if (pid == 0) /* Child */
#ifdef WITH_SELINUX
security_context_t prev_context;
#endif
- char err_buf[ERR_BUF_LEN];
if (asprintf (&tmpname, "%s.%sXXXXXX", file, program) < 0)
{
if (lock_database () != 0)
{
fprintf (stderr, _("Cannot lock `%s': already locked.\n"), file);
- free(tmpname);
return E_PWDBUSY;
}
user will create them. */
if (errno != ENOENT)
{
- fprintf (stderr, _("File dose not exist: %s\n"),
- strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fprintf (stderr, "%s: %s\n", file, strerror (errno));
close (new_fd);
unlink (tmpname);
ulckpwdf ();
{
if (write (new_fd, buffer, cnt) != cnt)
{
- fprintf (stderr, _("Cannot copy `%s': %s\n"),
- file, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ fprintf (stderr, _("Cannot copy `%s': %s\n"),
+ file, strerror (errno));
cnt = -1;
break;
}
if (cnt < 0) /* Remove file if copy failed. */
{
fprintf (stderr, _("Cannot copy `%s': %s\n"),
- file, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ file, strerror (errno));
close (old_fd);
close (new_fd);
unlink (tmpname);
if (fstat (old_fd, &orig))
{
fprintf (stderr, _("Can't stat `%s': %m\n"), file);
- close(old_fd);
- free(tmpname);
return E_FAILURE;
}
close (old_fd);
if (stat (tmpname, &before))
{
fprintf (stderr, _("Can't stat `%s': %m\n"), tmpname);
- free(tmpname);
return E_FAILURE;
}
if (stat (tmpname, &after))
{
fprintf (stderr, _("Can't stat `%s': %m\n"), tmpname);
- free (tmpname);
return E_FAILURE;
}
/* Set modes of temporary file to the from the original one. */
if (chmod (tmpname, orig.st_mode) < 0)
{
- fprintf (stderr,
+ fprintf (stderr,
_("Cannot change permissions for `%s': %s\n"),
- tmpname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ tmpname, strerror (errno));
unlink (tmpname);
- free (tmpname);
return E_FAILURE;
}
if (chown (tmpname, orig.st_uid, orig.st_gid) < 0)
{
fprintf (stderr,
_("Cannot change owner/group for `%s': %s\n"),
- tmpname, strerror_r (errno, err_buf, ERR_BUF_LEN));
+ tmpname, strerror (errno));
unlink (tmpname);
- free (tmpname);
return E_FAILURE;
}
_("Warning: cannot create backup file: %m\n"));
rename (tmpname, file);
}
- free (old);
}
ulckpwdf ();