From a145ddda284570e57413e37f025c3657205e17d8 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Fri, 25 May 2018 20:01:54 +0200 Subject: Repository scheme updated to new layout NOTE: This commit just moves files around, without actually fixing the Makefiles and specfile. See follow up commits which resolve this. --- src/consoletype.1 | 44 -------------------------------------------- src/genhostid.1 | 12 ------------ src/ifup.8 | 36 ------------------------------------ src/netreport.1 | 22 ---------------------- src/sushell | 5 ----- src/sushell.8 | 16 ---------------- src/usernetctl.8 | 39 --------------------------------------- src/usleep.1 | 30 ------------------------------ 8 files changed, 204 deletions(-) delete mode 100644 src/consoletype.1 delete mode 100644 src/genhostid.1 delete mode 100644 src/ifup.8 delete mode 100644 src/netreport.1 delete mode 100755 src/sushell delete mode 100644 src/sushell.8 delete mode 100644 src/usernetctl.8 delete mode 100644 src/usleep.1 (limited to 'src') diff --git a/src/consoletype.1 b/src/consoletype.1 deleted file mode 100644 index ebd1d88c..00000000 --- a/src/consoletype.1 +++ /dev/null @@ -1,44 +0,0 @@ -.TH CONSOLETYPE 1 "Red Hat, Inc" "RH" \" -*- nroff -*- -.SH NAME -\fBconsoletype -\- print type of the console connected to standard input -.SH SYNOPSIS -\fBconsoletype [\fIstdout\fR] [\fIfg\fR] -.SH DESCRIPTION -\fBconsoletype -prints the type of console connected to standard input, and checks -whether the console connected to standard input is the current -foreground virtual console. With no arguments, it prints -\fIvt\fR -if console is a virtual terminal (/dev/tty* or /dev/console device if not on -a serial console), -\fIserial\fR -if standard input is a serial console (/dev/console or /dev/ttyS*) and -\fIpty\fR -if standard input is a pseudo terminal. -.SH RETURN VALUE -\fBconsoletype -when passed no arguments returns -.TP -\fI0 -if on virtual terminal -.TP -\fI1 -if on serial console -.TP -\fI2 -if on a pseudo terminal. -.TP -When passed the \fIstdout\fR argument, \fBconsoletype\fR returns -.TP -\fI0 -in all cases, and prints the console type to stdout. -.TP -When passed the \fIfg\fR argument, \fBconsoletype\fR returns -.TP -\fI0 -if the console connected to standard input is the current virtual -terminal -.TP -\fI1 -otherwise. diff --git a/src/genhostid.1 b/src/genhostid.1 deleted file mode 100644 index 436d9537..00000000 --- a/src/genhostid.1 +++ /dev/null @@ -1,12 +0,0 @@ -.TH GENHOSTID 1 -.SH NAME -genhostid \- generate and set a hostid for the current host -.SH SYNOPSIS -.B genhostid - -.SH DESCRIPTION -\fBgenhostid\fR generates a random hostid and stores it in /etc/hostid, -if /etc/hostid does not already exist. - -.SH "SEE ALSO" -hostid(1), gethostid(2), sethostid(2) diff --git a/src/ifup.8 b/src/ifup.8 deleted file mode 100644 index 1cf1fcd8..00000000 --- a/src/ifup.8 +++ /dev/null @@ -1,36 +0,0 @@ -.\" Copyright 2009 Petr Lautrbach (plautrba@redhat.com) -.TH ifup 8 2009-10-27 "" "System Administration tools and Daemons" -.SH NAME -ifup - bring a network interface up - -ifdown - take a network interface down -.SH SYNOPSIS -.B ifup CONFIG [boot] - -.B ifdown CONFIG - -.SH DESCRIPTION -The -.B ifup -and -.B ifdown -commands may be used to configure (or, respec- -tively, deconfigure) network interfaces based on interface definitions -in the files /etc/sysconfig/network and /etc/sysconfig/network-scripts/ifcfg- - -These scripts take one argument normally: the name of the configuration -(e.g. eth0). They are called with a second argument of "boot" -during the boot sequence so that devices that are not meant to -be brought up on boot (ONBOOT=no, see below) can be ignored at -that time. - -.SH FILES -.TP -\fB/etc/sysconfig/network\fR - -.TP -\fB/etc/sysconfig/network-scripts/ifcfg-\fR -The file defining an interface. - -.SH "SEE ALSO" -/usr/share/doc/initscripts-*/sysconfig.txt diff --git a/src/netreport.1 b/src/netreport.1 deleted file mode 100644 index 75ed0747..00000000 --- a/src/netreport.1 +++ /dev/null @@ -1,22 +0,0 @@ -.TH NETREPORT 1 "Red Hat, Inc." "RH" \" -*- nroff -*- -.SH NAME -netreport \- request notification of network interface changes -.SH SYNOPSIS -.B netreport -\fI[\fP-r\fI]\fP -.SH DESCRIPTION -.B netreport -tells the network management scripts to send a SIGIO signal -to the process which called netreport when any network interface -status changes occur. -.SH OPTIONS -.TP -.B -r -Remove the current request (if any) for the calling process. -.PP -.SH NOTES -If a program does not call netreport with the -.B -r -option before it exits, and another process is created with the -same PID before any changes take place in interface status, it -is possible that the new process will receive a spurious SIGIO. diff --git a/src/sushell b/src/sushell deleted file mode 100755 index 7d969416..00000000 --- a/src/sushell +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -[ -z "$SUSHELL" ] && SUSHELL=/bin/bash - -exec $SUSHELL diff --git a/src/sushell.8 b/src/sushell.8 deleted file mode 100644 index 9832a732..00000000 --- a/src/sushell.8 +++ /dev/null @@ -1,16 +0,0 @@ -.TH SUSHELL 8 "Red Hat, Inc" \" -*- nroff -*- -.SH NAME -sushell \- execute the single-user shell -.SH SYNOPSIS -.B sushell -.SH DESCRIPTION -.B sushell -executes the single-user shell. By default, this is -\fI/bin/bash\fP -This can be configured via the -.B SUSHELL -environment variable. -.SH NOTES -.B sushell -is an implementation detail, required for proper SELinux -usage. It is not intended to be run regularly. diff --git a/src/usernetctl.8 b/src/usernetctl.8 deleted file mode 100644 index 2fb84da1..00000000 --- a/src/usernetctl.8 +++ /dev/null @@ -1,39 +0,0 @@ -.TH USERNETCTL 8 "Red Hat, Inc." "RHS" \" -*- nroff -*- -.SH NAME -usernetctl \- allow a user to manipulate a network interface if permitted -.SH SYNOPSIS -.B usernetctl -\fIinterface-name\fP up\fI|\fPdown\fI|\fPreport -.SH DESCRIPTION -.B usernetctl -checks to see if users are allowed to manipulate the network interface -specified by \fIinterface-name\fP, and then tries to bring the network -interface up or down, if up or down was specified on the command line, -or returns true or false status (respectively) if the report option was -specified. - -.B usernetctl -is not really meant to be called directly by users, though it currently -works fine that way. It is used as a wrapper by the ifup and ifdown -scripts, so that users can do exactly the same thing as root: -.nf -ifup \fIinterface-name\fP -ifdown \fIinterface-name\fP -.fi -and \fBifup\fP and \fBifdown\fP will call usernetctl automatically to -allow the interface status change. -.SH OPTIONS -.TP -.I "\fIinterface-name" -The name of the network interface to check; for example, "ppp0". For -backwards compatibility, "ifcfg-ppp0" and -"/etc/sysconfig/network-scripts/ifcfg-ppp0" are also supported. -.TP -up\fI|\fPdown -Attempt to bring the interface up or down. -.TP -report -Report on whether users can bring the interface up or down. -.SH NOTES -Alternate device configurations may inherit the default configuration's -permissions. diff --git a/src/usleep.1 b/src/usleep.1 deleted file mode 100644 index 30db2bad..00000000 --- a/src/usleep.1 +++ /dev/null @@ -1,30 +0,0 @@ -.TH USLEEP 1 "Red Hat, Inc" \" -*- nroff -*- -.SH NAME -usleep \- sleep some number of microseconds -.SH SYNOPSIS -.B usleep -[\fInumber\fP] -.SH DESCRIPTION -.B usleep -sleeps some number of microseconds. The default is 1. -.SH WARNING -.B usleep -has been deprecated, and will be removed in near future. Use sleep(1) instead. -.SH OPTIONS -\fI--usage\fP -Show short usage message. -.TP -\fI--help, -?\fP -Print help information. -.TP -\fI-v, --version\fP -Print version information. -.SH BUGS -Probably not accurate on many machines down to the microsecond. Count -on precision only to -4 or maybe -5. -.SH AUTHOR -Donald Barnes -.br -Erik Troan -.SH SEE ALSO -sleep(1) -- cgit v1.2.1 From 87db0f22359504a9d8bef2beb889de60830610be Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Fri, 25 May 2018 20:59:34 +0200 Subject: src/Makefile simplified & updated to new repository layout The rules have been unified, build results are now in build/ subfolder, and it uses GNU naming for the system paths... --- src/.gitignore | 11 +---- src/Makefile | 127 +++++++++++++++++++++++++++++++++-------------------- src/build/.gitkeep | 0 3 files changed, 80 insertions(+), 58 deletions(-) create mode 100644 src/build/.gitkeep (limited to 'src') diff --git a/src/.gitignore b/src/.gitignore index 01d63587..a007feab 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,10 +1 @@ -usernetctl -netreport -testd -usleep -ipcalc -getkey -ppp-watch -consoletype -genhostid -rename_device +build/* diff --git a/src/Makefile b/src/Makefile index d4df499b..68222ac5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,54 +1,85 @@ -CFLAGS+=$(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE -fPIE -LDFLAGS+=$(RPM_LD_FLAGS) -pie -z relro -z now +# Basic Makefile for compiling & installing the files. +# +# Supports standard GNU Makefile variables for specifying the paths: +# * prefix +# * bindir +# * sbindir +# * libdir +# * DESTDIR +# -PROGS=usernetctl netreport usleep \ - consoletype genhostid rename_device -CONSOLE_INIT_OBJS=console_init.o shvar.o -USLEEP_OBJS=usleep.o +SHELL = /bin/bash -mandir=/usr/share/man +# Normally /usr/local is used. However, it does not make sense for us to use it +# here, as it just complicates things even further. +prefix = /usr +bindir = $(prefix)/bin +sbindir = $(prefix)/sbin +libdir = $(prefix)/lib -all: $(PROGS) +CC = gcc +CFLAGS += $(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE -fPIE +LDFLAGS += $(RPM_LD_FLAGS) -pie -z relro -z now + +PROGS = consoletype genhostid netreport rename_device usernetctl usleep + +all: $(PROGS) + +install: all + install -m 0755 -d $(DESTDIR)$(bindir) + install -m 0755 -d $(DESTDIR)$(sbindir) + install -m 0755 -d $(DESTDIR)$(libdir)/udev + install -m 0755 build/usleep $(DESTDIR)$(bindir) + install -m 0755 build/consoletype $(DESTDIR)$(sbindir) + install -m 0755 build/genhostid $(DESTDIR)$(sbindir) + install -m 0755 build/netreport $(DESTDIR)$(sbindir) + install -m 0755 build/usernetctl $(DESTDIR)$(sbindir) + install -m 0755 build/rename_device $(DESTDIR)$(libdir)/udev clean: - rm -f $(PROGS) *.o *~ - -install: - mkdir -p $(ROOT)/usr/bin $(ROOT)/usr/sbin $(ROOT)$(mandir)/man{1,8} $(ROOT)/etc $(ROOT)/usr/lib/udev - install -m 755 usleep $(ROOT)/usr/bin/usleep - install -m 4755 usernetctl $(ROOT)/usr/sbin/usernetctl - install -m 2755 netreport $(ROOT)/usr/sbin/netreport - install -m 755 genhostid $(ROOT)/usr/sbin/genhostid - install -m 755 consoletype $(ROOT)/usr/sbin/consoletype - install -m 755 sushell $(ROOT)/usr/sbin/sushell - install -m 755 rename_device $(ROOT)/usr/lib/udev/rename_device - install -m 644 genhostid.1 $(ROOT)$(mandir)/man1 - install -m 644 netreport.1 $(ROOT)$(mandir)/man1 - install -m 644 usleep.1 $(ROOT)$(mandir)/man1 - install -m 644 usernetctl.8 $(ROOT)$(mandir)/man8 - install -m 644 consoletype.1 $(ROOT)$(mandir)/man1 - install -m 644 ifup.8 $(ROOT)$(mandir)/man8 - install -m 644 sushell.8 $(ROOT)$(mandir)/man8 - ln -s ifup.8 $(ROOT)$(mandir)/man8/ifdown.8 - -usleep: $(USLEEP_OBJS) - $(CC) $(LDFLAGS) -o $@ $(USLEEP_OBJS) -lpopt - -usernetctl.o: usernetctl.c - $(CC) $(CFLAGS) -c usernetctl.c -o usernetctl.o - -usernetctl: usernetctl.c usernetctl.o - $(CC) $(LDFLAGS) -o $@ $@.o - -netreport.o: netreport.c - $(CC) $(CFLAGS) -c netreport.c -o netreport.o - -netreport: netreport.o - $(CC) $(LDFLAGS) -o $@ $@.o - -shvar.o: shvar.c - $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -c shvar.c -o shvar.o - -rename_device: rename_device.c - $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -o $@ $< $(LDFLAGS) `pkg-config glib-2.0 --libs` + rm -f build/* + +consoletype: build/consoletype.o + $(CC) $(LDFLAGS) -o build/$@ $^ + +build/consoletype.o: consoletype.c + $(CC) $(CFLAGS) -c -o $@ $^ + + +genhostid: build/genhostid.o + $(CC) $(LDFLAGS) -o build/$@ $^ + +build/genhostid.o: genhostid.c + $(CC) $(CFLAGS) -c -o $@ $^ + + +netreport: build/netreport.o + $(CC) $(LDFLAGS) -o build/$@ $^ + +build/netreport.o: netreport.c + $(CC) $(CFLAGS) -c -o $@ $^ + + +rename_device: build/rename_device.o + $(CC) $(LDFLAGS) -o build/$@ $^ `pkg-config glib-2.0 --libs` + +build/rename_device.o: rename_device.c + $(CC) $(CFLAGS) -c -o $@ $^ `pkg-config glib-2.0 --cflags` + + +usernetctl: build/usernetctl.o + $(CC) $(LDFLAGS) -o build/$@ $^ + +build/usernetctl.o: usernetctl.c + $(CC) $(CFLAGS) -c -o $@ $^ + + +usleep: build/usleep.o + $(CC) $(LDFLAGS) -o build/$@ $^ -lpopt + +build/usleep.o: usleep.c + $(CC) $(CFLAGS) -c -o $@ $^ + +build/shvar.o: shvar.c + $(CC) $(CFLAGS) -c -o $@ $^ `pkg-config glib-2.0 --cflags` diff --git a/src/build/.gitkeep b/src/build/.gitkeep new file mode 100644 index 00000000..e69de29b -- cgit v1.2.1 From 023b56d02bc93e9cf5aff0efcf73a30b7d7780f1 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Thu, 17 May 2018 16:24:15 +0200 Subject: src/shvar.* removed No longer build or used by anything else in initscripts. --- src/Makefile | 4 - src/shvar.c | 393 ----------------------------------------------------------- src/shvar.h | 103 ---------------- 3 files changed, 500 deletions(-) delete mode 100644 src/shvar.c delete mode 100644 src/shvar.h (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 68222ac5..193d5af2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -79,7 +79,3 @@ usleep: build/usleep.o build/usleep.o: usleep.c $(CC) $(CFLAGS) -c -o $@ $^ - - -build/shvar.o: shvar.c - $(CC) $(CFLAGS) -c -o $@ $^ `pkg-config glib-2.0 --cflags` diff --git a/src/shvar.c b/src/shvar.c deleted file mode 100644 index 9817d9a4..00000000 --- a/src/shvar.c +++ /dev/null @@ -1,393 +0,0 @@ -/* - * shvar.c - * - * Implementation of non-destructively reading/writing files containing - * only shell variable declarations and full-line comments. - * - * Includes explicit inheritance mechanism intended for use with - * Red Hat Linux ifcfg-* files. There is no protection against - * inheritance loops; they will generally cause stack overflows. - * Furthermore, they are only intended for one level of inheritance; - * the value setting algorithm assumes this. - * - * Copyright 1999,2000 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "shvar.h" - -/* Open the file , returning a shvarFile on success and NULL on failure. - Add a wrinkle to let the caller specify whether or not to create the file - (actually, return a structure anyway) if it doesn't exist. */ -static shvarFile * -svOpenFile(const char *name, gboolean create) -{ - shvarFile *s = NULL; - int closefd = 0; - - s = g_malloc0(sizeof(shvarFile)); - - s->fd = open(name, O_RDWR); /* NOT O_CREAT */ - if (s->fd == -1) { - /* try read-only */ - s->fd = open(name, O_RDONLY); /* NOT O_CREAT */ - if (s->fd != -1) closefd = 1; - } - s->fileName = g_strdup(name); - - if (s->fd != -1) { - struct stat buf; - char *p, *q; - - if (fstat(s->fd, &buf) < 0) goto bail; - s->arena = g_malloc0(buf.st_size + 1); - - if (read(s->fd, s->arena, buf.st_size) < 0) goto bail; - - /* we'd use g_strsplit() here, but we want a list, not an array */ - for(p = s->arena; (q = strchr(p, '\n')) != NULL; p = q + 1) { - s->lineList = g_list_append(s->lineList, g_strndup(p, q - p)); - } - - /* closefd is set if we opened the file read-only, so go ahead and - close it, because we can't write to it anyway */ - if (closefd) { - close(s->fd); - s->fd = -1; - } - - return s; - } - - if (create) { - return s; - } - -bail: - if (s->fd != -1) close(s->fd); - if (s->arena) g_free (s->arena); - if (s->fileName) g_free (s->fileName); - g_free (s); - return NULL; -} - -/* Open the file , return shvarFile on success, NULL on failure */ -shvarFile * -svNewFile(const char *name) -{ - return svOpenFile(name, FALSE); -} - -/* Create a new file structure, returning actual data if the file exists, - * and a suitable starting point if it doesn't. */ -shvarFile * -svCreateFile(const char *name) -{ - return svOpenFile(name, TRUE); -} - -/* remove escaped characters in place */ -static void -unescape(char *s) { - int len, i; - - len = strlen(s); - if ((s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) { - i = len - 2; - memmove(s, s+1, i); - s[i+1] = '\0'; - len = i; - } - for (i = 0; i < len; i++) { - if (s[i] == '\\') { - memmove(s+i, s+i+1, len-(i+1)); - len--; - } - s[len] = '\0'; - } -} - - -/* create a new string with all necessary characters escaped. - * caller must free returned string - */ -static const char escapees[] = "\"'\\$~`"; /* must be escaped */ -static const char spaces[] = " \t|&;()<>"; /* only require "" */ -static char * -escape(const char *s) { - char *new; - int i, j, mangle = 0, space = 0; - int newlen, slen; - static int esclen, splen; - - if (!esclen) esclen = strlen(escapees); - if (!splen) splen = strlen(spaces); - slen = strlen(s); - - for (i = 0; i < slen; i++) { - if (strchr(escapees, s[i])) mangle++; - if (strchr(spaces, s[i])) space++; - } - if (!mangle && !space) return strdup(s); - - newlen = slen + mangle + 3; /* 3 is extra ""\0 */ - new = g_malloc0(newlen); - if (!new) return NULL; - - j = 0; - new[j++] = '"'; - for (i = 0; i < slen; i++) { - if (strchr(escapees, s[i])) { - new[j++] = '\\'; - } - new[j++] = s[i]; - } - new[j++] = '"'; - g_assert(j == slen + mangle + 2); /* j is the index of the '\0' */ - - return new; -} - -/* Get the value associated with the key, and leave the current pointer - * pointing at the line containing the value. The char* returned MUST - * be freed by the caller. - */ -char * -svGetValue(shvarFile *s, const char *key) -{ - char *value = NULL; - char *line; - char *keyString; - int len; - - g_assert(s); - g_assert(key); - - keyString = g_malloc0(strlen(key) + 2); - strcpy(keyString, key); - keyString[strlen(key)] = '='; - len = strlen(keyString); - - for (s->current = s->lineList; s->current; s->current = s->current->next) { - line = s->current->data; - if (!strncmp(keyString, line, len)) { - value = g_strdup(line + len); - unescape(value); - break; - } - } - g_free(keyString); - - if (value) { - if (value[0]) { - return value; - } else { - g_free(value); - return NULL; - } - } - if (s->parent) value = svGetValue(s->parent, key); - return value; -} - -/* return 1 if resolves to any truth value (e.g. "yes", "y", "true") - * return 0 if resolves to any non-truth value (e.g. "no", "n", "false") - * return otherwise - */ -int -svTrueValue(shvarFile *s, const char *key, int def) -{ - char *tmp; - int returnValue = def; - - tmp = svGetValue(s, key); - if (!tmp) return returnValue; - - if ( (!strcasecmp("yes", tmp)) || - (!strcasecmp("true", tmp)) || - (!strcasecmp("t", tmp)) || - (!strcasecmp("y", tmp)) ) returnValue = 1; - else - if ( (!strcasecmp("no", tmp)) || - (!strcasecmp("false", tmp)) || - (!strcasecmp("f", tmp)) || - (!strcasecmp("n", tmp)) ) returnValue = 0; - - g_free (tmp); - return returnValue; -} - - -/* Set the variable equal to the value . - * If does not exist, and the pointer is set, append - * the key=value pair after that line. Otherwise, prepend the pair - * to the top of the file. Here's the algorithm, as the C code - * seems to be rather dense: - * - * if (value == NULL), then: - * if val2 (parent): change line to key= or append line key= - * if val1 (this) : delete line - * else noop - * else use this table: - * val2 - * NULL value other - * v NULL append line noop append line - * a - * l value noop noop noop - * 1 - * other change line delete line change line - * - * No changes are ever made to the parent config file, only to the - * specific file passed on the command line. - * - */ -void -svSetValue(shvarFile *s, const char *key, const char *value) -{ - char *newval = NULL, *val1 = NULL, *val2 = NULL; - char *keyValue; - - g_assert(s); - g_assert(key); - /* value may be NULL */ - - if (value) newval = escape(value); - keyValue = g_strdup_printf("%s=%s", key, newval ? newval : ""); - - val1 = svGetValue(s, key); - if (val1 && newval && !strcmp(val1, newval)) goto bail; - if (s->parent) val2 = svGetValue(s->parent, key); - - if (!newval || !newval[0]) { - /* delete value somehow */ - if (val2) { - /* change/append line to get key= */ - if (s->current) s->current->data = keyValue; - else s->lineList = g_list_append(s->lineList, keyValue); - s->freeList = g_list_append(s->freeList, keyValue); - s->modified = 1; - } else if (val1) { - /* delete line */ - s->lineList = g_list_remove_link(s->lineList, s->current); - g_list_free_1(s->current); - s->modified = 1; - goto bail; /* do not need keyValue */ - } - goto end; - } - - if (!val1) { - if (val2 && !strcmp(val2, newval)) goto end; - /* append line */ - s->lineList = g_list_append(s->lineList, keyValue); - s->freeList = g_list_append(s->freeList, keyValue); - s->modified = 1; - goto end; - } - - /* deal with a whole line of noops */ - if (val1 && !strcmp(val1, newval)) goto end; - - /* At this point, val1 && val1 != value */ - if (val2 && !strcmp(val2, newval)) { - /* delete line */ - s->lineList = g_list_remove_link(s->lineList, s->current); - g_list_free_1(s->current); - s->modified = 1; - goto bail; /* do not need keyValue */ - } else { - /* change line */ - if (s->current) s->current->data = keyValue; - else s->lineList = g_list_append(s->lineList, keyValue); - s->freeList = g_list_append(s->freeList, keyValue); - s->modified = 1; - } - -end: - if (newval) free(newval); - if (val1) free(val1); - if (val2) free(val2); - return; - -bail: - if (keyValue) free (keyValue); - goto end; -} - -/* Write the current contents iff modified. Returns -1 on error - * and 0 on success. Do not write if no values have been modified. - * The mode argument is only used if creating the file, not if - * re-writing an existing file, and is passed unchanged to the - * open() syscall. - */ -int -svWriteFile(shvarFile *s, int mode) -{ - FILE *f; - int tmpfd; - - if (s->modified) { - if (s->fd == -1) - s->fd = open(s->fileName, O_WRONLY|O_CREAT, mode); - if (s->fd == -1) - return -1; - if (ftruncate(s->fd, 0) < 0) - return -1; - - tmpfd = dup(s->fd); - f = fdopen(tmpfd, "w"); - fseek(f, 0, SEEK_SET); - for (s->current = s->lineList; s->current; s->current = s->current->next) { - char *line = s->current->data; - fprintf(f, "%s\n", line); - } - fclose(f); - } - - return 0; -} - - -/* Close the file descriptor (if open) and delete the shvarFile. - * Returns -1 on error and 0 on success. - */ -int -svCloseFile(shvarFile *s) -{ - - g_assert(s); - - if (s->fd != -1) close(s->fd); - - g_free(s->arena); - for (s->current = s->freeList; s->current; s->current = s->current->next) { - g_free(s->current->data); - } - g_free(s->fileName); - g_list_free(s->freeList); - g_list_free(s->lineList); /* implicitly frees s->current */ - g_free(s); - return 0; -} diff --git a/src/shvar.h b/src/shvar.h deleted file mode 100644 index 46fb6b7b..00000000 --- a/src/shvar.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * shvar.h - * - * Interface for non-destructively reading/writing files containing - * only shell variable declarations and full-line comments. - * - * Includes explicit inheritance mechanism intended for use with - * Red Hat Linux ifcfg-* files. There is no protection against - * inheritance loops; they will generally cause stack overflows. - * Furthermore, they are only intended for one level of inheritance; - * the value setting algorithm assumes this. - * - * Copyright 1999 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -#ifndef _SHVAR_H -#define _SHVAR_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef struct _shvarFile shvarFile; -struct _shvarFile { - char *fileName; /* read-only */ - int fd; /* read-only */ - char *arena; /* ignore */ - GList *lineList; /* read-only */ - GList *freeList; /* ignore */ - GList *current; /* set implicitly or explicitly, - points to element of lineList */ - shvarFile *parent; /* set explicitly */ - int modified; /* ignore */ -}; - - -/* Create the file , return shvarFile on success, NULL on failure */ -shvarFile * -svCreateFile(const char *name); - -/* Open the file , return shvarFile on success, NULL on failure */ -shvarFile * -svNewFile(const char *name); - -/* Get the value associated with the key, and leave the current pointer - * pointing at the line containing the value. The char* returned MUST - * be freed by the caller. - */ -char * -svGetValue(shvarFile *s, const char *key); - -/* return 1 if resolves to any truth value (e.g. "yes", "y", "true") - * return 0 if resolves to any non-truth value (e.g. "no", "n", "false") - * return otherwise - */ -int -svTrueValue(shvarFile *s, const char *key, int def); - -/* Set the variable equal to the value . - * If does not exist, and the pointer is set, append - * the key=value pair after that line. Otherwise, prepend the pair - * to the top of the file. - */ -void -svSetValue(shvarFile *s, const char *key, const char *value); - - -/* Write the current contents iff modified. Returns -1 on error - * and 0 on success. Do not write if no values have been modified. - * The mode argument is only used if creating the file, not if - * re-writing an existing file, and is passed unchanged to the - * open() syscall. - */ -int -svWriteFile(shvarFile *s, int mode); - -/* Close the file descriptor (if open) and delete the shvarFile. - * Returns -1 on error and 0 on success. - */ -int -svCloseFile(shvarFile *s); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* ! _SHVAR_H */ -- cgit v1.2.1 From 9b2dbe00100d4e1077404b9d781f35adad979467 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Thu, 24 May 2018 16:06:03 +0200 Subject: netreport functionality dropped This concept is quite outdated, and not sane to use at all. --- src/Makefile | 10 +------- src/netreport.c | 72 --------------------------------------------------------- 2 files changed, 1 insertion(+), 81 deletions(-) delete mode 100644 src/netreport.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 193d5af2..8825e45b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -21,7 +21,7 @@ CC = gcc CFLAGS += $(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE -fPIE LDFLAGS += $(RPM_LD_FLAGS) -pie -z relro -z now -PROGS = consoletype genhostid netreport rename_device usernetctl usleep +PROGS = consoletype genhostid rename_device usernetctl usleep all: $(PROGS) @@ -32,7 +32,6 @@ install: all install -m 0755 build/usleep $(DESTDIR)$(bindir) install -m 0755 build/consoletype $(DESTDIR)$(sbindir) install -m 0755 build/genhostid $(DESTDIR)$(sbindir) - install -m 0755 build/netreport $(DESTDIR)$(sbindir) install -m 0755 build/usernetctl $(DESTDIR)$(sbindir) install -m 0755 build/rename_device $(DESTDIR)$(libdir)/udev @@ -53,13 +52,6 @@ build/genhostid.o: genhostid.c $(CC) $(CFLAGS) -c -o $@ $^ -netreport: build/netreport.o - $(CC) $(LDFLAGS) -o build/$@ $^ - -build/netreport.o: netreport.c - $(CC) $(CFLAGS) -c -o $@ $^ - - rename_device: build/rename_device.o $(CC) $(LDFLAGS) -o build/$@ $^ `pkg-config glib-2.0 --libs` diff --git a/src/netreport.c b/src/netreport.c deleted file mode 100644 index 204a77d7..00000000 --- a/src/netreport.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1997-2002 Red Hat, Inc. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -#include -#include -#include -#include -#include -#include - -/* this will be running setgid root, so be careful! */ - -static void -usage(void) { - fprintf(stderr, "usage: netreport [-r]\n"); - exit(1); -} - -#define ADD 1 -#define DEL 0 -int main(int argc, char ** argv) { - int action = ADD; - /* more than long enough for "/run/netreport/\0" */ - char netreport_name[64]; - int netreport_file; - - if (argc > 2) { - usage(); - } - - if (argc > 1) { - if (argc == 2 && strcmp(argv[1], "-r") == 0) { - action = DEL; - } else { - usage(); - } - } - - snprintf(netreport_name, sizeof(netreport_name), - "/run/netreport/%d", getppid()); - if (action == ADD) { - netreport_file = open(netreport_name, - O_EXCL|O_CREAT|O_WRONLY|O_TRUNC|O_NOFOLLOW, 0); - if (netreport_file == -1) { - if (errno != EEXIST) { - perror("Could not create netreport file"); - exit (1); - } - } else { - close(netreport_file); - } - } else { - /* ignore errors; not much we can do, won't hurt anything */ - unlink(netreport_name); - } - - return 0; -} -- cgit v1.2.1 From d8746bfc9d8d944082726cdcbee634b1ec72d45f Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Wed, 30 May 2018 17:10:02 +0200 Subject: src/usleep.c: GCC warnings fixed --- src/usleep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/usleep.c b/src/usleep.c index e5e3077d..58ab2d79 100644 --- a/src/usleep.c +++ b/src/usleep.c @@ -28,13 +28,13 @@ #include "popt.h" -int main(int argc, char **argv) { +int main(const int argc, const char **argv) { unsigned long count; poptContext optCon; int showVersion = 0; int showOot = 0; int rc; - char * countStr = NULL; + const char * countStr = NULL; struct poptOption options[] = { { "version", 'v', POPT_ARG_NONE, &showVersion, 0, "Display the version of this program, and exit" }, -- cgit v1.2.1 From ecc23fe5b61bc5d501cd2fcffffcf5ab87269317 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Wed, 30 May 2018 17:46:05 +0200 Subject: src/genhostid.c: fixed to not override /etc/hostid if it already exists Resolves: #105 --- src/genhostid.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/genhostid.c b/src/genhostid.c index c7561c9e..f6253bec 100644 --- a/src/genhostid.c +++ b/src/genhostid.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * + * */ #include @@ -20,19 +20,28 @@ #include #include #include -int -main (void) + +int main (void) { struct stat st; long int n; - if (stat ("/etc/hostid", &st) == 0 && S_ISREG (st.st_mode) - && st.st_size >= sizeof (n)) + + /* + * NOTE: gethostid() always returns 32-bit identifier, and st_size field + * of stat structure represents total size of file, in bytes. + */ + + if (stat ("/etc/hostid", &st) == 0 && + S_ISREG (st.st_mode) && st.st_size == 4) { return 0; + } + int fd = open ("/dev/random", O_RDONLY); - if (fd == -1 || read (fd, &n, sizeof (n)) != sizeof (n)) - { - srand48 ((long int) time (NULL) ^ (long int) getpid ()); - n = lrand48 (); - } - return sethostid ((int32_t)n); + + if (fd == -1 || read (fd, &n, sizeof (n)) != sizeof (n)) { + srand48 ((long int) time (NULL) ^ (long int) getpid ()); + n = lrand48 (); + } + + return sethostid ((int32_t) n); } -- cgit v1.2.1 From 8e30047757e8a8947eee3edc0feebcac7289334b Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Thu, 31 May 2018 13:49:21 +0200 Subject: src/genhostid.c: deprecation warning added --- src/genhostid.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/genhostid.c b/src/genhostid.c index f6253bec..79dcb92e 100644 --- a/src/genhostid.c +++ b/src/genhostid.c @@ -20,12 +20,16 @@ #include #include #include +#include int main (void) { struct stat st; long int n; + fprintf(stderr, "warning: genhostid is now deprecated, and will be removed in the near future!\n" + "warning: use systemd-machine-id-setup (1) instead! More info: 'man 5 machine-id'\n"); + /* * NOTE: gethostid() always returns 32-bit identifier, and st_size field * of stat structure represents total size of file, in bytes. -- cgit v1.2.1 From 0d6b1e0188dcf74bf43d54a18ce5dc5fb8679339 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Thu, 31 May 2018 14:07:42 +0200 Subject: src/consoletype.c: deprecation warning added --- src/consoletype.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/consoletype.c b/src/consoletype.c index 929969a4..dc3bd119 100644 --- a/src/consoletype.c +++ b/src/consoletype.c @@ -30,7 +30,10 @@ int main(int argc, char **argv) char *type; int maj, min, ret = 0, fg = -1; struct stat sb; - + + fprintf(stderr, "warning: consoletype is now deprecated, and will be removed in the near future!\n" + "warning: use tty (1) instead! More info: 'man 1 tty'\n"); + fstat(0, &sb); maj = major(sb.st_rdev); min = minor(sb.st_rdev); -- cgit v1.2.1 From 2aa3d2035190c7838c355b986749104a1d9f6e64 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Mon, 4 Jun 2018 17:30:09 +0200 Subject: src/usernetctl.c: GCC warnings about unused return value suppressed --- src/usernetctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/usernetctl.c b/src/usernetctl.c index 9e127604..d966dc71 100644 --- a/src/usernetctl.c +++ b/src/usernetctl.c @@ -155,6 +155,7 @@ main(int argc, char ** argv) { char * cmd = NULL; int report = 0; char tmp; + int ignored_retval __attribute__((unused)); if (argc != 3) usage(); @@ -235,9 +236,9 @@ main(int argc, char ** argv) { /* pppd wants the real uid to be the same as the effective (god only knows why when it works fine setuid out of the box) */ - setuid(geteuid()); + ignored_retval = setuid(geteuid()); /* Drop user gid (for temp files, SELinux) */ - setgid(0); + ignored_retval = setgid(0); execle(cmd, cmd, ifaceConfig, NULL, safeEnviron); fprintf(stderr, "exec of %s failed: %s\n", cmd, strerror(errno)); -- cgit v1.2.1 From d12c5f3d31391eefaf330c9598e1195d96935025 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Mon, 4 Jun 2018 17:32:34 +0200 Subject: src/rename_device.c: GCC warnings about unused return value suppressed --- src/rename_device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rename_device.c b/src/rename_device.c index 6d6030eb..c39f447d 100644 --- a/src/rename_device.c +++ b/src/rename_device.c @@ -281,6 +281,7 @@ char *get_config_by_hwaddr(char *hwaddr, char *current) { void take_lock() { int count = 0; int lockfd; + ssize_t ignored_retval __attribute__((unused)); while (1) { lockfd = open(LOCKFILE, O_RDWR|O_CREAT|O_EXCL, 0644); @@ -288,7 +289,7 @@ void take_lock() { char buf[32]; snprintf(buf,32,"%d\n",getpid()); - write(lockfd,buf,strlen(buf)); + ignored_retval = write(lockfd,buf,strlen(buf)); close(lockfd); break; } else if (errno == EACCES) @@ -304,7 +305,7 @@ void take_lock() { fd = open(LOCKFILE, O_RDONLY); if (fd == -1) break; - read(fd,buf,32); + ignored_retval = read(fd,buf,32); close(fd); pid = atoi(buf); if (pid && pid != 1) { -- cgit v1.2.1