add directory gnu

This commit is contained in:
gohigh
2024-02-19 00:24:47 -05:00
parent 32616db5a4
commit a40f4cadb0
5086 changed files with 1860970 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
# Copyright (C) 1991 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
# You should have received a copy of the GNU Library General Public
# License along with the GNU C Library; see the file COPYING.LIB. If
# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.
#
# Sub-makefile for pwd portion of the library.
#
subdir := pwd
routines := pwdopen pwdread fgetpwent getpw getpwent getpwnam getpwuid putpwent
include ../Rules

View File

@@ -0,0 +1,40 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <pwd.h>
/* Read one entry from the given stream. */
struct passwd *
DEFUN(fgetpwent, (stream), FILE *stream)
{
static PTR info = NULL;
if (info == NULL)
{
info = __pwdalloc();
if (info == NULL)
return(NULL);
}
return(__pwdread(stream, info));
}

View File

@@ -0,0 +1,48 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <stdio.h>
#include <pwd.h>
/* Re-construct the password-file line for the given uid
in the given buffer. This knows the format that the caller
will expect, but this need not be the format of the password file. */
int
DEFUN(getpw, (uid, buf), __uid_t uid AND register char *buf)
{
register struct passwd *p;
if (buf == NULL)
{
errno = EINVAL;
return -1;
}
p = getpwuid (uid);
if (p == NULL)
return -1;
if (sprintf (buf, "%s:%s:%u:%u:%s:%s:%s", p->pw_name, p->pw_passwd,
p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell) < 0)
return -1;
return 0;
}

View File

@@ -0,0 +1,67 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h>
#include <stdio.h>
#include <pwd.h>
static FILE *stream = NULL;
/* Rewind the stream. */
void
DEFUN_VOID(setpwent)
{
if (stream != NULL)
rewind(stream);
}
/* Close the stream. */
void
DEFUN_VOID(endpwent)
{
if (stream != NULL)
{
(void) fclose(stream);
stream = NULL;
}
}
/* Return one entry from the password file. */
struct passwd *
DEFUN_VOID(getpwent)
{
static PTR info = NULL;
if (info == NULL)
{
info = __pwdalloc();
if (info == NULL)
return(NULL);
}
if (stream == NULL)
{
stream = __pwdopen();
if (stream == NULL)
return(NULL);
}
return(__pwdread(stream, info));
}

View File

@@ -0,0 +1,50 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <pwd.h>
/* Search for an entry with a matching name. */
struct passwd *
DEFUN(getpwnam, (name), register CONST char *name)
{
static PTR info = NULL;
register FILE *stream;
register struct passwd *p;
if (info == NULL)
{
info = __pwdalloc();
if (info == NULL)
return(NULL);
}
stream = __pwdopen();
if (stream == NULL)
return(NULL);
while ((p = __pwdread(stream, info)) != NULL)
if (!strcmp(p->pw_name, name))
break;
(void) fclose(stream);
return(p);
}

View File

@@ -0,0 +1,50 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h>
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
/* Search for an entry with a matching uid. */
struct passwd *
DEFUN(getpwuid, (uid), register uid_t uid)
{
static PTR info;
register FILE *stream;
register struct passwd *p;
if (info == NULL)
{
info = __pwdalloc();
if (info == NULL)
return(NULL);
}
stream = __pwdopen();
if (stream == NULL)
return(NULL);
while ((p = __pwdread(stream, info)) != NULL)
if (p->pw_uid == uid)
break;
(void) fclose(stream);
return(p);
}

View File

@@ -0,0 +1,43 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <stdio.h>
#include <pwd.h>
/* Write an entry to the given stream.
This must know the format of the password file. */
int
DEFUN(putpwent, (p, stream), register CONST struct passwd *p AND FILE *stream)
{
if (p == NULL || stream == NULL)
{
errno = EINVAL;
return -1;
}
if (fprintf (stream, "%s:%s:%u:%u:%s:%s\n",
p->pw_name, p->pw_passwd,
p->pw_uid, p->pw_gid,
p->pw_gecos, p->pw_shell) < 0)
return(-1);
return(0);
}

View File

@@ -0,0 +1,88 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
/*
* POSIX Standard: 9.2.2 User Database Access <pwd.h>
*/
#ifndef _PWD_H
#define _PWD_H 1
#include <features.h>
#include <gnu/types.h>
/* The passwd structure. */
struct passwd
{
char *pw_name; /* Username. */
char *pw_passwd; /* Password. */
__uid_t pw_uid; /* User ID. */
__gid_t pw_gid; /* Group ID. */
char *pw_gecos; /* Real name. */
char *pw_dir; /* Home directory. */
char *pw_shell; /* Shell program. */
};
#if defined(__USE_SVID) || defined(__USE_GNU)
#define __need_FILE
#include <stdio.h>
#endif
#ifdef __USE_GNU
/* Return a new stream open on the password file. */
extern FILE *EXFUN(__pwdopen, (NOARGS));
/* Read a password entry from STREAM, filling in P.
Return the `struct passwd' of P if successful, NULL on failure. */
extern struct passwd *EXFUN(__pwdread, (FILE *__stream, PTR __p));
/* Return a chunk of memory containing pre-initialized data for __pwdread. */
extern PTR EXFUN(__pwdalloc, (NOARGS));
#endif
#if defined(__USE_SVID) || defined(__USE_MISC)
/* Rewind the password-file stream. */
extern void EXFUN(setpwent, (NOARGS));
/* Close the password-file stream. */
extern void EXFUN(endpwent, (NOARGS));
/* Read an entry from the password-file stream, opening it if necessary. */
extern struct passwd *EXFUN(getpwent, (NOARGS));
#endif
#ifdef __USE_SVID
/* Read an entry from STREAM. */
extern struct passwd *EXFUN(fgetpwent, (FILE *__stream));
/* Write the given entry onto the given stream. */
extern int EXFUN(putpwent, (CONST struct passwd *__p, FILE *__f));
#endif
/* Search for an entry with a matching user ID. */
extern struct passwd *EXFUN(getpwuid, (__uid_t __uid));
/* Search for an entry with a matching username. */
extern struct passwd *EXFUN(getpwnam, (CONST char *__name));
#endif /* pwd.h */

View File

@@ -0,0 +1,28 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stdio.h>
#include <pwd.h>
/* Return a new stream open on the password file. */
FILE *
DEFUN_VOID(__pwdopen)
{
return(fopen("/etc/passwd", "r"));
}

View File

@@ -0,0 +1,116 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
#include <sys/types.h>
/* This is the function that all the others are based on.
The format of the password file is known only here. */
/* Structure containing info kept by each __pwdread caller. */
typedef struct
{
char *buf;
size_t buflen;
struct passwd p;
} pwdread_info;
/* Return a chunk of memory containing a pre-initialized `pwdread_info'. */
PTR
DEFUN_VOID(__pwdalloc)
{
pwdread_info *info = (PTR) malloc (sizeof(pwdread_info));
if (info == NULL)
return NULL;
info->buf = NULL;
info->buflen = 0;
return info;
}
/* Read a password entry from STREAM, filling in P. */
struct passwd *
DEFUN(__pwdread, (stream, p), FILE *stream AND PTR CONST p)
{
register pwdread_info *CONST info = (pwdread_info *) p;
char *start, *end;
/* Idiocy checks. */
if (stream == NULL)
{
errno = EINVAL;
return NULL;
}
do
if (__getline (&info->buf, &info->buflen, stream) == -1)
return NULL;
while (info->buf[0] == '#');
start = info->buf;
end = strchr (start, ':');
if (end == NULL)
return NULL;
*end = '\0';
info->p.pw_name = start;
start = end + 1;
end = strchr (start, ':');
if (end == NULL)
return NULL;
*end = '\0';
info->p.pw_passwd = start;
info->p.pw_uid = (uid_t) strtol (end + 1, &end, 10);
if (*end != ':')
return NULL;
info->p.pw_gid = (gid_t) strtol (end + 1, &end, 10);
if (*end != ':')
return NULL;
start = end + 1;
end = strchr (start, ':');
if (end == NULL)
return NULL;
*end = '\0';
info->p.pw_gecos = start;
start = end + 1;
end = strchr (start, ':');
if (end == NULL)
return NULL;
*end = '\0';
info->p.pw_dir = start;
start = end + 1;
end = strchr (start, '\n');
if (end == NULL)
return NULL;
*end = '\0';
info->p.pw_shell = start;
return &info->p;
}