Update glcdtest, hostname, id.

This commit is contained in:
Serge
2022-05-27 17:22:07 -07:00
parent 75302a4eec
commit c213981071
5 changed files with 22 additions and 13 deletions

View File

@@ -13,3 +13,4 @@ struct group *getgrgid(gid_t gid);
void setgrent(void); void setgrent(void);
void endgrent(void); void endgrent(void);
int setgroups(size_t size, const gid_t *list); int setgroups(size_t size, const gid_t *list);
int getgrouplist(char *uname, gid_t agroup, gid_t *groups, int *grpcnt);

View File

@@ -143,6 +143,9 @@ int getopt (int argc, char * const argv[], const char *optstring);
extern char *optarg; /* getopt(3) external variables */ extern char *optarg; /* getopt(3) external variables */
extern int opterr, optind, optopt; extern int opterr, optind, optopt;
int gethostname(char *name, int namelen);
int sethostname(char *name, int namelen);
#ifndef _VA_LIST_ #ifndef _VA_LIST_
# ifdef __GNUC__ # ifdef __GNUC__
# define va_list __builtin_va_list /* For Gnu C */ # define va_list __builtin_va_list /* For Gnu C */

View File

@@ -7,6 +7,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <glcd.h> #include <glcd.h>
#include <string.h> #include <string.h>
#include <unistd.h>
int glcd; int glcd;
@@ -267,7 +268,7 @@ int main()
banner("Bouncy Lines"); banner("Bouncy Lines");
sleep(1); sleep(1);
bouncy_lines(500); bouncy_lines(500);
sleep(1); sleep(1);
cls(); cls();
banner("Stretchy Box"); banner("Stretchy Box");

View File

@@ -34,6 +34,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
int int
main(argc,argv) main(argc,argv)

View File

@@ -159,16 +159,18 @@ pretty(pw)
else else
(void)printf("uid\t%u\n", rid); (void)printf("uid\t%u\n", rid);
if ((eid = geteuid()) != rid) if ((eid = geteuid()) != rid) {
if (pw = getpwuid(eid)) if ((pw = getpwuid(eid)))
(void)printf("euid\t%s", pw->pw_name); (void)printf("euid\t%s", pw->pw_name);
else else
(void)printf("euid\t%u", eid); (void)printf("euid\t%u", eid);
if ((rid = getgid()) != (eid = getegid())) }
if (gr = getgrgid(rid)) if ((rid = getgid()) != (eid = getegid())) {
if ((gr = getgrgid(rid)))
(void)printf("rgid\t%s\n", gr->gr_name); (void)printf("rgid\t%s\n", gr->gr_name);
else else
(void)printf("rgid\t%u\n", rid); (void)printf("rgid\t%u\n", rid);
}
(void)printf("groups\t"); (void)printf("groups\t");
group(NULL, 1); group(NULL, 1);
} }
@@ -185,20 +187,20 @@ current()
id = getuid(); id = getuid();
(void)printf("uid=%u", id); (void)printf("uid=%u", id);
if (pw = getpwuid(id)) if ((pw = getpwuid(id)))
(void)printf("(%s)", pw->pw_name); (void)printf("(%s)", pw->pw_name);
if ((eid = geteuid()) != id) { if ((eid = geteuid()) != id) {
(void)printf(" euid=%u", eid); (void)printf(" euid=%u", eid);
if (pw = getpwuid(eid)) if ((pw = getpwuid(eid)))
(void)printf("(%s)", pw->pw_name); (void)printf("(%s)", pw->pw_name);
} }
id = getgid(); id = getgid();
(void)printf(" gid=%u", id); (void)printf(" gid=%u", id);
if (gr = getgrgid(id)) if ((gr = getgrgid(id)))
(void)printf("(%s)", gr->gr_name); (void)printf("(%s)", gr->gr_name);
if ((eid = getegid()) != id) { if ((eid = getegid()) != id) {
(void)printf(" egid=%u", eid); (void)printf(" egid=%u", eid);
if (gr = getgrgid(eid)) if ((gr = getgrgid(eid)))
(void)printf("(%s)", gr->gr_name); (void)printf("(%s)", gr->gr_name);
} }
ngroups = getgroups(NGROUPS, groups); ngroups = getgroups(NGROUPS, groups);
@@ -209,7 +211,7 @@ current()
if (lastid == id) if (lastid == id)
continue; continue;
(void)printf(fmt, id); (void)printf(fmt, id);
if (gr = getgrgid(id)) if ((gr = getgrgid(id)))
(void)printf("(%s)", gr->gr_name); (void)printf("(%s)", gr->gr_name);
} }
(void)printf("\n"); (void)printf("\n");
@@ -237,7 +239,7 @@ user(pw)
continue; continue;
(void)printf(fmt, id); (void)printf(fmt, id);
fmt = " %u"; fmt = " %u";
if (gr = getgrgid(id)) if ((gr = getgrgid(id)))
(void)printf("(%s)", gr->gr_name); (void)printf("(%s)", gr->gr_name);
lastid = id; lastid = id;
} }
@@ -266,7 +268,7 @@ group(pw, nflag)
if (lastid == (id = groups[cnt])) if (lastid == (id = groups[cnt]))
continue; continue;
if (nflag) { if (nflag) {
if (gr = getgrgid(id)) if ((gr = getgrgid(id)))
(void)printf(fmt, gr->gr_name); (void)printf(fmt, gr->gr_name);
else else
(void)printf(*fmt == ' ' ? " %u" : "%u", (void)printf(*fmt == ' ' ? " %u" : "%u",
@@ -293,12 +295,13 @@ who(u)
* Translate user argument into a pw pointer. First, try to * Translate user argument into a pw pointer. First, try to
* get it as specified. If that fails, try it as a number. * get it as specified. If that fails, try it as a number.
*/ */
if (pw = getpwnam(u)) if ((pw = getpwnam(u)))
return(pw); return(pw);
id = strtol(u, &ep, 10); id = strtol(u, &ep, 10);
if (*u && !*ep && (pw = getpwuid(id))) if (*u && !*ep && (pw = getpwuid(id)))
return(pw); return(pw);
errx(1, "%s: No such user", u); errx(1, "%s: No such user", u);
return 0;
} }
void void