LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how can i restrict /etc/motd for a specific user (https://www.linuxquestions.org/questions/programming-9/how-can-i-restrict-etc-motd-for-a-specific-user-109423/)

mtest 10-28-2003 06:29 AM

how can i restrict /etc/motd for a specific user
 
when i kept a message in /etc/motd all the users are getting whenever the users logged in. but can any body say how to restrict the message for a specific users and not for all

SaTaN 10-28-2003 06:41 AM

A sincere piece of advice ....
Looks like this is the 3rd post on the same question.
Don't post so many posts regarding the same topic. One post will do.
It is irritating to see so many posts on same topic / same question
Posting several posts will not help you get more replies.
http://www.linuxquestions.org/rules.php

Plz refer to this also for more details

LogicG8 10-28-2003 11:07 AM

The best choice for getting a specific message to a user is email
but if you want to have a message sent to a user on login you
you could edit the global shell start up files in /etc with a little bit
of shell wizardry to give them notice. Be warned if their home
script has a simple clear command in it or they have fortune output
something large or anything like that your message will be
lost. In bash it would probably be something like

if [ -e /path/to/msgs/${LOGNAME} ] ; then
cat /path/to/msgs/${LOGNAME}
rm /path/to/msgs/${LOGNAME}
fi

You would need to be careful with permissions to avoid
users reading/writing/removing each others messsages.

Good luck.

mtest 10-29-2003 12:04 AM

hello Mr SATAN, thanks for ur sincere advice. I didn't get the correct reply. thats why i am posting several times
if i am troublig u. forgive me

Hko 10-29-2003 11:22 AM

If you do not get the right reply, IMHO you should comment on that in the same thread. Maybe your question was not clear to the person who replied. Posting another is quite annoying for people who are trying to help you.

jim mcnamara 10-29-2003 01:56 PM

Satan & Hko -

Consider this: you should simply report the thread if it bothers you. Mods can clobber/move a thread. Mods can remonstrate.
You posts didn't help the problem at all, IMO.

One "corrective" post is more than enough.

Also - mtest's English writing skills are probably why he doesn't get the answer he needs, because he has trouble phrasing it so we get it. I, for one, do not really know what he's trying to do.

It looks like there is one user, X, who is not supposed to execute some common file or files at login. A solution would be to use the system-wide login script (on this box it's /etc/profile ) and do everything inside there. But since there is so little detailed information, I can't answer constructively. I made one guess bad earlier.

LogicG8 10-29-2003 02:15 PM

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.

Hko 10-29-2003 02:17 PM

Quote:

Originally posted by jim mcnamara
Consider this: you should simply report the thread if it bothers you. Mods can clobber/move a thread. Mods can remonstrate.
OK. I think you are right here. In the future, I'll either report to a moderator or do nothing.

Quote:

One "corrective" post is more than enough.
True.

Quote:

Also - mtest's English writing skills are probably why he doesn't get the answer he needs, because he has trouble phrasing it so we get it. I, for one, do not really know what he's trying to do.
Probably true, but IMO that's not a reason to start multiple threads, with different titles, about the same thing.

mtest 10-30-2003 01:41 AM

sorry for troubling u people all.


All times are GMT -5. The time now is 05:22 AM.