LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-28-2003, 06:29 AM   #1
mtest
LQ Newbie
 
Registered: Oct 2003
Location: India
Posts: 22

Rep: Reputation: 15
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
 
Old 10-28-2003, 06:41 AM   #2
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 33
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
 
Old 10-28-2003, 11:07 AM   #3
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
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.

Last edited by LogicG8; 10-28-2003 at 02:01 PM.
 
Old 10-29-2003, 12:04 AM   #4
mtest
LQ Newbie
 
Registered: Oct 2003
Location: India
Posts: 22

Original Poster
Rep: Reputation: 15
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
 
Old 10-29-2003, 11:22 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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.
 
Old 10-29-2003, 01:56 PM   #6
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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.
 
Old 10-29-2003, 02:15 PM   #7
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
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.
 
Old 10-29-2003, 02:17 PM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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.
 
Old 10-30-2003, 01:41 AM   #9
mtest
LQ Newbie
 
Registered: Oct 2003
Location: India
Posts: 22

Original Poster
Rep: Reputation: 15
sorry for troubling u people all.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I restrict a particular user to use only XFCE? rsamurti Slackware - Installation 8 10-25-2006 08:36 AM
How to restrict user permissions solnitza Linux - Newbie 5 08-26-2005 03:58 PM
restrict user to folder disorderly Linux - Security 5 03-02-2005 09:49 PM
To restrict a specific user simi_virgo Linux - Newbie 1 02-26-2005 12:03 AM
how to restrict the user simi_virgo Linux - Newbie 2 02-25-2005 06:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration