diff options
Diffstat (limited to 'lib/libcompat')
-rw-r--r-- | lib/libcompat/4.3/re_comp.3 | 117 | ||||
-rw-r--r-- | lib/libcompat/4.3/re_comp.c | 88 | ||||
-rw-r--r-- | lib/libcompat/4.3/rexec.3 | 128 | ||||
-rw-r--r-- | lib/libcompat/4.3/rexec.c | 383 | ||||
-rw-r--r-- | lib/libcompat/4.4/cuserid.3 | 85 | ||||
-rw-r--r-- | lib/libcompat/4.4/cuserid.c | 53 | ||||
-rw-r--r-- | lib/libcompat/Makefile | 22 | ||||
-rw-r--r-- | lib/libcompat/Makefile.depend | 12 |
8 files changed, 888 insertions, 0 deletions
diff --git a/lib/libcompat/4.3/re_comp.3 b/lib/libcompat/4.3/re_comp.3 new file mode 100644 index 000000000000..504519a77459 --- /dev/null +++ b/lib/libcompat/4.3/re_comp.3 @@ -0,0 +1,117 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd June 4, 1993 +.Dt RE_COMP 3 +.Os +.Sh NAME +.Nm re_comp , +.Nm re_exec +.Nd regular expression handler +.Sh LIBRARY +.Lb libcompat +.Sh SYNOPSIS +.In unistd.h +.Ft char * +.Fn re_comp "const char *s" +.Ft int +.Fn re_exec "const char *s" +.Sh DESCRIPTION +.Bf -symbolic +This interface is made obsolete by +.Xr regex 3 . +.Ef +.Pp +The +.Fn re_comp +function +compiles a string into an internal form suitable for pattern matching. +The +.Fn re_exec +function +checks the argument string against the last string passed to +.Fn re_comp . +.Pp +The +.Fn re_comp +function +returns 0 if the string +.Fa s +was compiled successfully; otherwise a string containing an +error message is returned. +If +.Fn re_comp +is passed 0 or a null string, it returns without changing the currently +compiled regular expression. +.Pp +The +.Fn re_exec +function +returns 1 if the string +.Fa s +matches the last compiled regular expression, 0 if the string +.Fa s +failed to match the last compiled regular expression, and \-1 if the compiled +regular expression was invalid (indicating an internal error). +.Pp +The strings passed to both +.Fn re_comp +and +.Fn re_exec +may have trailing or embedded newline characters; +they are terminated by +.Dv NUL Ns s . +The regular expressions recognized are described in the manual entry for +.Xr ed 1 , +given the above difference. +.Sh DIAGNOSTICS +The +.Fn re_exec +function +returns \-1 for an internal error. +.Pp +The +.Fn re_comp +function +returns +.Dq no previous regular expression +or one of the strings generated by +.Xr regerror 3 . +.Sh SEE ALSO +.Xr ed 1 , +.Xr egrep 1 , +.Xr ex 1 , +.Xr fgrep 1 , +.Xr grep 1 , +.Xr regex 3 +.Sh HISTORY +The +.Fn re_comp +and +.Fn re_exec +functions appeared in +.Bx 4.0 . diff --git a/lib/libcompat/4.3/re_comp.c b/lib/libcompat/4.3/re_comp.c new file mode 100644 index 000000000000..a45f06769c57 --- /dev/null +++ b/lib/libcompat/4.3/re_comp.c @@ -0,0 +1,88 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * James da Silva at the University of Maryland at College Park. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +/* + * Compatibility routines that implement the old re_comp/re_exec interface in + * terms of the regcomp/regexec interface. It's possible that some programs + * rely on dark corners of re_comp/re_exec and won't work with this version, + * but most programs should be fine. + */ + +#include <regex.h> +#include <stddef.h> +#include <unistd.h> + +static regex_t re_regexp; +static int re_gotexp; +static char re_errstr[100]; + +char * +re_comp(const char *s) +{ + int rc; + + if (s == NULL || *s == '\0') { + if (!re_gotexp) + return __DECONST(char *, + "no previous regular expression"); + return (NULL); + } + + if (re_gotexp) { + regfree(&re_regexp); + re_gotexp = 0; + } + + rc = regcomp(&re_regexp, s, REG_EXTENDED); + if (rc == 0) { + re_gotexp = 1; + return (NULL); + } + + regerror(rc, &re_regexp, re_errstr, sizeof(re_errstr)); + re_errstr[sizeof(re_errstr) - 1] = '\0'; + return (re_errstr); +} + +int +re_exec(const char *s) +{ + int rc; + + if (!re_gotexp) + return (-1); + rc = regexec(&re_regexp, s, 0, NULL, 0); + return (rc == 0 ? 1 : 0); +} diff --git a/lib/libcompat/4.3/rexec.3 b/lib/libcompat/4.3/rexec.3 new file mode 100644 index 000000000000..165e7002ebf3 --- /dev/null +++ b/lib/libcompat/4.3/rexec.3 @@ -0,0 +1,128 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd June 4, 1993 +.Dt REXEC 3 +.Os +.Sh NAME +.Nm rexec +.Nd return stream to a remote command +.Sh LIBRARY +.Lb libcompat +.Sh SYNOPSIS +.Ft int +.Fn rexec "char **ahost" "int inport" "char *user" "char *passwd" "char *cmd" "int *fd2p" +.Sh DESCRIPTION +.Bf -symbolic +This interface is obsoleted by +.Xr rcmd 3 . +.Ef +.Pp +The +.Fn rexec +function +looks up the host +.Fa *ahost +using +.Xr gethostbyname 3 , +returning \-1 if the host does not exist. +Otherwise +.Fa *ahost +is set to the standard name of the host. +If a username and password are both specified, then these +are used to authenticate to the foreign host; otherwise +the environment and then the user's +.Pa .netrc +file in his +home directory are searched for appropriate information. +If all this fails, the user is prompted for the information. +.Pp +The port +.Fa inport +specifies which well-known +.Tn DARPA +Internet port to use for +the connection; the call +.Fn getservbyname \*qexec\*q \*qtcp\*q +(see +.Xr getservent 3 ) +will return a pointer to a structure, which contains the +necessary port. +The protocol for connection is described in detail in +.Xr rexecd 8 . +.Pp +If the connection succeeds, +a socket in the Internet domain of type +.Dv SOCK_STREAM +is returned to +the caller, and given to the remote command as +.Dv stdin +and +.Dv stdout . +If +.Fa fd2p +is non-zero, then an auxiliary channel to a control +process will be setup, and a descriptor for it will be placed +in +.Fa *fd2p . +The control process will return diagnostic +output from the command (unit 2) on this channel, and will also +accept bytes on this channel as being +.Ux +signal numbers, to be +forwarded to the process group of the command. +The diagnostic +information returned does not include remote authorization failure, +as the secondary connection is set up after authorization has been +verified. +If +.Fa fd2p +is 0, then the +.Dv stderr +(unit 2 of the remote +command) will be made the same as the +.Dv stdout +and no +provision is made for sending arbitrary signals to the remote process, +although you may be able to get its attention by using out-of-band data. +.Sh SEE ALSO +.Xr rcmd 3 , +.Xr rexecd 8 +.Sh HISTORY +The +.Fn rexec +function appeared in +.Bx 4.2 . +.Sh BUGS +The +.Fn rexec +function sends the unencrypted password across the network. +.Pp +The underlying service is considered a big security hole and therefore +not enabled on many sites, see +.Xr rexecd 8 +for explanations. diff --git a/lib/libcompat/4.3/rexec.c b/lib/libcompat/4.3/rexec.c new file mode 100644 index 000000000000..b2f37a09c0fb --- /dev/null +++ b/lib/libcompat/4.3/rexec.c @@ -0,0 +1,383 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include <sys/types.h> +#include <sys/uio.h> +#include <sys/socket.h> +#include <sys/param.h> +#include <sys/stat.h> + +#include <netinet/in.h> + +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <netdb.h> +#include <errno.h> +#include <ctype.h> +#include <err.h> +#include <stdlib.h> +#include <unistd.h> + +int rexecoptions; + +/* + * Options and other state info. + */ +struct macel { + char mac_name[9]; /* macro name */ + char *mac_start; /* start of macro in macbuf */ + char *mac_end; /* end of macro in macbuf */ +}; + +int macnum; /* number of defined macros */ +struct macel macros[16]; +char macbuf[4096]; + +static FILE *cfile; + +#define DEFAULT 1 +#define LOGIN 2 +#define PASSWD 3 +#define ACCOUNT 4 +#define MACDEF 5 +#define ID 10 +#define MACH 11 + +static char tokval[100]; + +static struct toktab { + char *tokstr; + int tval; +} toktab[]= { + { "default", DEFAULT }, + { "login", LOGIN }, + { "password", PASSWD }, + { "passwd", PASSWD }, + { "account", ACCOUNT }, + { "machine", MACH }, + { "macdef", MACDEF }, + { NULL, 0 } +}; + +static int +token() +{ + char *cp; + int c; + struct toktab *t; + + if (feof(cfile) || ferror(cfile)) + return (0); + while ((c = getc(cfile)) != EOF && + (c == '\n' || c == '\t' || c == ' ' || c == ',')) + continue; + if (c == EOF) + return (0); + cp = tokval; + if (c == '"') { + while ((c = getc(cfile)) != EOF && c != '"') { + if (c == '\\') + c = getc(cfile); + *cp++ = c; + } + } else { + *cp++ = c; + while ((c = getc(cfile)) != EOF + && c != '\n' && c != '\t' && c != ' ' && c != ',') { + if (c == '\\') + c = getc(cfile); + *cp++ = c; + } + } + *cp = 0; + if (tokval[0] == 0) + return (0); + for (t = toktab; t->tokstr; t++) + if (!strcmp(t->tokstr, tokval)) + return (t->tval); + return (ID); +} + +static int +ruserpass(char *host, char **aname, char **apass, char **aacct) +{ + char *hdir, buf[BUFSIZ], *tmp; + char myname[MAXHOSTNAMELEN], *mydomain; + int t, i, c, usedefault = 0; + struct stat stb; + + hdir = getenv("HOME"); + if (hdir == NULL) + hdir = "."; + if (strlen(hdir) + 8 > sizeof(buf)) + return (0); + (void) sprintf(buf, "%s/.netrc", hdir); + cfile = fopen(buf, "r"); + if (cfile == NULL) { + if (errno != ENOENT) + warn("%s", buf); + return (0); + } + if (gethostname(myname, sizeof(myname)) < 0) + myname[0] = '\0'; + if ((mydomain = strchr(myname, '.')) == NULL) + mydomain = ""; +next: + while ((t = token())) switch(t) { + + case DEFAULT: + usedefault = 1; + /* FALL THROUGH */ + + case MACH: + if (!usedefault) { + if (token() != ID) + continue; + /* + * Allow match either for user's input host name + * or official hostname. Also allow match of + * incompletely-specified host in local domain. + */ + if (strcasecmp(host, tokval) == 0) + goto match; + if ((tmp = strchr(host, '.')) != NULL && + strcasecmp(tmp, mydomain) == 0 && + strncasecmp(host, tokval, tmp - host) == 0 && + tokval[tmp - host] == '\0') + goto match; + continue; + } + match: + while ((t = token()) && t != MACH && t != DEFAULT) switch(t) { + + case LOGIN: + if (token()) + if (*aname == NULL) { + *aname = malloc((unsigned) strlen(tokval) + 1); + (void) strcpy(*aname, tokval); + } else { + if (strcmp(*aname, tokval)) + goto next; + } + break; + case PASSWD: + if ((*aname == NULL || strcmp(*aname, "anonymous")) && + fstat(fileno(cfile), &stb) >= 0 && + (stb.st_mode & 077) != 0) { + warnx("Error: .netrc file is readable by others."); + warnx("Remove password or make file unreadable by others."); + goto bad; + } + if (token() && *apass == NULL) { + *apass = malloc((unsigned) strlen(tokval) + 1); + (void) strcpy(*apass, tokval); + } + break; + case ACCOUNT: + if (fstat(fileno(cfile), &stb) >= 0 + && (stb.st_mode & 077) != 0) { + warnx("Error: .netrc file is readable by others."); + warnx("Remove account or make file unreadable by others."); + goto bad; + } + if (token() && *aacct == NULL) { + *aacct = malloc((unsigned) strlen(tokval) + 1); + (void) strcpy(*aacct, tokval); + } + break; + case MACDEF: + while ((c=getc(cfile)) != EOF && + (c == ' ' || c == '\t')) + ; + if (c == EOF || c == '\n') { + printf("Missing macdef name argument.\n"); + goto bad; + } + if (macnum == 16) { + printf("Limit of 16 macros have already been defined\n"); + goto bad; + } + tmp = macros[macnum].mac_name; + *tmp++ = c; + for (i=0; i < 8 && (c=getc(cfile)) != EOF && + !isspace(c); ++i) { + *tmp++ = c; + } + if (c == EOF) { + printf("Macro definition missing null line terminator.\n"); + goto bad; + } + *tmp = '\0'; + if (c != '\n') { + while ((c=getc(cfile)) != EOF && c != '\n'); + } + if (c == EOF) { + printf("Macro definition missing null line terminator.\n"); + goto bad; + } + if (macnum == 0) { + macros[macnum].mac_start = macbuf; + } + else { + macros[macnum].mac_start = macros[macnum-1].mac_end + 1; + } + tmp = macros[macnum].mac_start; + while (tmp != macbuf + 4096) { + if ((c=getc(cfile)) == EOF) { + printf("Macro definition missing null line terminator.\n"); + goto bad; + } + *tmp = c; + if (*tmp == '\n') { + if (*(tmp-1) == '\0') { + macros[macnum++].mac_end = tmp - 1; + break; + } + *tmp = '\0'; + } + tmp++; + } + if (tmp == macbuf + 4096) { + printf("4K macro buffer exceeded\n"); + goto bad; + } + break; + default: + warnx("Unknown .netrc keyword %s", tokval); + break; + } + goto done; + } +done: + (void) fclose(cfile); + return (0); +bad: + (void) fclose(cfile); + return (-1); +} + +int +rexec(char **ahost, int rport, char *name, char *pass, char *cmd, int *fd2p) +{ + struct sockaddr_in sin, sin2, from; + struct hostent *hp; + u_short port; + int s, timo = 1, s3; + char c, *acct; + + hp = gethostbyname(*ahost); + if (hp == NULL) { + herror(*ahost); + return (-1); + } + *ahost = hp->h_name; + acct = NULL; + ruserpass(hp->h_name, &name, &pass, &acct); + free(acct); +retry: + s = socket(AF_INET, SOCK_STREAM, 0); + if (s < 0) { + perror("rexec: socket"); + return (-1); + } + sin.sin_family = hp->h_addrtype; + sin.sin_port = rport; + bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); + if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + if (errno == ECONNREFUSED && timo <= 16) { + (void) close(s); + sleep(timo); + timo *= 2; + goto retry; + } + perror(hp->h_name); + (void) close(s); + return (-1); + } + port = 0; + if (fd2p == 0) + (void) write(s, "", 1); + else { + char num[8]; + int s2, sin2len; + + s2 = socket(AF_INET, SOCK_STREAM, 0); + if (s2 < 0) { + (void) close(s); + return (-1); + } + listen(s2, 1); + sin2len = sizeof (sin2); + if (getsockname(s2, (struct sockaddr *)&sin2, &sin2len) < 0 || + sin2len != sizeof (sin2)) { + perror("getsockname"); + (void) close(s2); + goto bad; + } + port = ntohs((u_short)sin2.sin_port); + (void) sprintf(num, "%hu", port); + (void) write(s, num, strlen(num)+1); + { int len = sizeof (from); + s3 = accept(s2, (struct sockaddr *)&from, &len); + close(s2); + if (s3 < 0) { + perror("accept"); + port = 0; + goto bad; + } + } + *fd2p = s3; + } + (void) write(s, name, strlen(name) + 1); + /* should public key encypt the password here */ + (void) write(s, pass, strlen(pass) + 1); + (void) write(s, cmd, strlen(cmd) + 1); + if (read(s, &c, 1) != 1) { + perror(*ahost); + goto bad; + } + if (c != 0) { + while (read(s, &c, 1) == 1) { + (void) write(2, &c, 1); + if (c == '\n') + break; + } + goto bad; + } + return (s); +bad: + if (port) + (void) close(*fd2p); + (void) close(s); + return (-1); +} diff --git a/lib/libcompat/4.4/cuserid.3 b/lib/libcompat/4.4/cuserid.3 new file mode 100644 index 000000000000..f3ecff8c84e9 --- /dev/null +++ b/lib/libcompat/4.4/cuserid.3 @@ -0,0 +1,85 @@ +.\" +.\" Copyright (c) 1995 Joerg Wunsch +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Joerg Wunsch +.\" 4. The name of the developer may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd April 10, 1995 +.Dt CUSERID 3 +.Os +.Sh NAME +.Nm cuserid +.Nd get user name associated with effective UID +.Sh LIBRARY +.Lb libcompat +.Sh SYNOPSIS +.In stdio.h +.Ft char * +.Fn cuserid "char *s" +.Sh DESCRIPTION +.Bf -symbolic +The +.Fn cuserid +function is made obsolete by +.Xr getpwuid 3 . +.Ef +.Pp +The function +.Fn cuserid +gets the user name associated with the effective UID of the current +process. +If the argument +.Fa s +is non-NULL, the name is copied to the buffer it points to, +and that address is being returned. +This buffer must provide space +for at least +.Em L_cuserid +characters. +The L_cuserid constant is defined in +.In stdio.h . +.Pp +If +.Fa s +is NULL, an internal array is used and its address will be returned. +.Sh RETURN VALUES +The +.Fn cuserid +function returns the address of an array in which the name has been stored. +.Pp +If the name associated with the effective UID of the current process +could not be found, either a null pointer will be returned, or +(if +.Fa s +is non-NULL) +the buffer +.Fa s +will be filled with a null string. +.Sh SEE ALSO +.Xr geteuid 2 , +.Xr getpwuid 3 diff --git a/lib/libcompat/4.4/cuserid.c b/lib/libcompat/4.4/cuserid.c new file mode 100644 index 000000000000..188330927897 --- /dev/null +++ b/lib/libcompat/4.4/cuserid.c @@ -0,0 +1,53 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include <pwd.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +char * +cuserid(char *s) +{ + struct passwd *pwd; + + if ((pwd = getpwuid(geteuid())) == NULL) { + if (s) + *s = '\0'; + return (s); + } + if (s) { + (void)strncpy(s, pwd->pw_name, L_cuserid); + return (s); + } + return (pwd->pw_name); +} diff --git a/lib/libcompat/Makefile b/lib/libcompat/Makefile new file mode 100644 index 000000000000..2612568a9da7 --- /dev/null +++ b/lib/libcompat/Makefile @@ -0,0 +1,22 @@ +PACKAGE=lib${LIB} +LIB= compat +CFLAGS+=-I${SRCTOP}/lib/libc/locale +NO_PIC= + +WARNS?= 0 + +.PATH: ${.CURDIR}/4.3 ${.CURDIR}/4.4 + +# compat 4.3 sources +SRCS+= re_comp.c rexec.c + +MAN+= 4.3/re_comp.3 4.3/rexec.3 + +MLINKS+=re_comp.3 re_exec.3 + +# compat 4.4 sources +SRCS+= cuserid.c + +MAN+= 4.4/cuserid.3 + +.include <bsd.lib.mk> diff --git a/lib/libcompat/Makefile.depend b/lib/libcompat/Makefile.depend new file mode 100644 index 000000000000..15a1f9c07f7c --- /dev/null +++ b/lib/libcompat/Makefile.depend @@ -0,0 +1,12 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + include/xlocale \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif |