I was bored at work and I just happen to have the sources for util-linux
kicking around on my harddrive so whipped up this little patch. I've been
meaning to take a closer look at the sources to getty for a project I'm doing
and since login is closely related I figured it'd be worth the sojourn.
Theory of operation:
You place a a list of names (1 per line) in /etc/motd.allow
Only those users in this list will receive the motd.
#include <stddisclaimer.h>
I didn't try it out as I have no interest in changing the behavior of login
(I also think it's silly thing to do) and I'm using my computer over ssh
but if you actually have a desire to do so here it is. I also wouldn't trust the
security on this thing as it's only lowly me cranking out this patch and it
hasn't been exposed to any peer review. Anyways here's the diff for it:
Code:
--- util-linux-2.12/login-utils/login.c 2003-07-13 14:11:31.000000000 -0400
+++ ./my_login.c 2003-10-29 14:54:12.000000000 -0500
@@ -183,6 +183,20 @@
static void motd (void);
static void dolastlog (int quiet);
+/* LogicG8's new functions in login.c */
+void read_user_list(void);
+int find_motd_user(char *);
+void chompspace(char *);
+char *skipspace(char *);
+/* End LogicG8's new functions */
+
+/* LogicG8;s new struct */
+struct ll_username {
+ struct ll_username *next;
+ char *name;
+};
+/* End LogicG8's new struct */
+
#ifdef CRYPTOCARD
#include "cryptocard.h"
#endif
@@ -227,6 +241,10 @@
static int failures = 1;
static pid_t pid;
+/* LogicG8's new global variables */
+struct ll_username *head;
+/* End LogicG8's new global variables */
+
#ifndef __linux__
struct sgttyb sgttyb;
struct tchars tc = {
@@ -1085,7 +1103,10 @@
struct stat st;
char *mail;
- motd();
+ read_user_list();
+ if (find_motd_user(pwd->pw_name) == 1) {
+ motd();
+ }
mail = getenv("MAIL");
if (mail && stat(mail, &st) == 0 && st.st_size != 0) {
if (st.st_mtime > st.st_atime)
@@ -1411,3 +1432,105 @@
sleep(SLEEP_EXIT_TIMEOUT);
exit(eval);
}
+
+
+/* LogicG8's additions for MOTD only for some users change */
+void read_user_list(void)
+{
+ FILE *user_list;
+ char buf[1024];
+ struct ll_username *curr;
+ char *str;
+
+ user_list = fopen("/etc/motd.allow", "r");
+ if (user_list == NULL) {
+ return;
+ }
+
+ /* Fill linked list with user names */
+ head = NULL;
+ while (fgets(buf, 1024, user_list) != NULL) {
+ /* skip comment lines */
+ if (buf[0] == '#') {
+ continue;
+ }
+ /* skip blank lines */
+ str = skipspace(buf);
+ chompspace(str);
+ if (str[0] == '\0') {
+ continue;
+ }
+
+ /* Form linked list */
+ if (head == NULL) {
+ /* starting new list */
+ head = (struct ll_username *)
+ malloc(sizeof(struct ll_username));
+ curr = head;
+ }
+ else {
+ /* append new node */
+ curr->next = (struct ll_username *)
+ malloc(sizeof(struct ll_username));
+ curr = curr->next;
+ }
+
+ /* Make sure malloc() didn't do us wrong */
+ if (curr == NULL) {
+ /* no memory at login, that's not a good sign */
+ return;
+ }
+ curr->next = NULL;
+ curr->name = (char *) malloc(strlen(buf) + 1);
+ if (curr->name == NULL) {
+ /* no memory at login, that's not a good sign */
+ return;
+ }
+ strcpy(curr->name, buf);
+ }
+ fclose(user_list);
+}
+
+/* Remove beginning whitspace */
+char *skipspace(char *strp)
+{
+ while (isspace(*strp) != 0) {
+ strp++;
+ }
+ return strp;
+}
+
+/* Remove trailing whitespace characters */
+void chompspace(char *str)
+{
+ int i;
+
+ i = strlen(str) - 1;
+ while ((i >= 0) && (isspace(str[i]) != 0)) {
+ str[i] = '\0';
+ i--;
+ }
+}
+
+int find_motd_user(char *name)
+{
+ struct ll_username *curr;
+ int found;
+
+ found = 0;
+ curr = head;
+ while ((curr != NULL) && (!found)) {
+ /* check username */
+ if ((curr->name != NULL)
+ && (name != NULL)
+ && (strcmp(name, curr->name) == 0)) {
+ /* We have a winner */
+ found = 1;
+ continue;
+ }
+
+ /* go to next node in list */
+ curr = curr->next;
+ }
+ return found;
+}
Have a nice day.