Hi Carol,

Now , I have come to know that Ctrl-D doesnot generate a signal but signals EOF.
So , i made the following changes in the code again.

*************************************************************************************************

char *getresponse(char *oldval)
    {
       char    resp[MAX_INPUT_LEN];
       char    *retval = NULL;
       int     resplen;
       char c;
       c=getchar();
       if(c==EOF)     {
             retval=&c;
             fprintf(stderr,MSG_CTRL,c);
             passwd_exit(CTRL);
       }    else   {

       (void) fgets(resp, sizeof (resp) - 1, stdin);
       resplen = strlen(resp) - 1;
       if (resp[resplen] == '\n')
               resp[resplen] = '\0';
       if (*resp != '\0' && strcmp(resp, oldval) != 0)
               retval = strdup(resp);
       return (retval);
    }
    }
***************************************************************************************************
n the above MSG_CTRL is a macro  defined  under the messages column as

#define MSG_CTRL        "\nYou have typed %c  (or Ctrl-D) which is
unacceptable\n"

And CTRL is a macro defined under the exit values column as

#define CTRLD    11   /*Exit value for typing Ctrl-D*/

****************************************************************************************************
Now we include this CTRLD macro under the switch-case block of
passwd-_exit() function
 before  the default block:

case CTRLD:
                  (void) fprintf(stderr, "%s\n", gettext(MSG_SHELL_UNCHANGED));
                   break;
*****************************************************************************************************

Now when we type 'passwd  -e' in the shell and when prompted for a new
shell, we type
Ctrl-D, the output is

You have pressed #(or Ctrl-D) which is unacceptable.
Login shell unchanged.
***************************************************************************************************
Note: # in the above refers to a unwanted character


I hope that this is definitely better than the previous one.

Regards,
Samir Kumar Mishra
3rd year , Electronics and Telecommunication Engg.
UCE, Burla(India)



On 12/27/07, samir kumar mishra <samirkumar.mishra at gmail.com> wrote:
> Hi Carol,
> This is Samir Kumar Mishra from India.
> I was just looking at this bug -6490935.(passwd does not handle
> Control-D input correctly)
>
> I think we can make the fix by doing the following changes in getresponse():
> **************************************************************************************************
>
> char *getresponse(char *oldval)
>      {
>       char    resp[MAX_INPUT_LEN];
>       char    *retval = NULL;
>       int     resplen;
>         char c;
>
>         if(c==-2)     {
>               retval=&c;
>               fprintf(stderr,MSG_CTRL,c);
>               passwd_exit(CTRL);
>         }    else   {
>
>       (void) fgets(resp, sizeof (resp) - 1, stdin);
>       resplen = strlen(resp) - 1;
>       if (resp[resplen] == '\n')
>               resp[resplen] = '\0';
>       if (*resp != '\0' && strcmp(resp, oldval) != 0)
>               retval = strdup(resp);
>       return (retval);
>      }
>      }
>
> ***************************************************************************************************
>
> In the above MSG_CTRL is a macro  defined  under the messages column as
>
> #define MSG_CTRL        "You have typed %c  (or Ctrl-D) which is
> unacceptable\n"
>
> And CTRL is a macro defined under the exit values column as
>
> #define CTRL    11   /*Exit value for typing Ctrl-D*/
>
> ***************************************************************************************************
>
> Now we include this CTRL macro under the switch-case block of
> passwd-_exit() function
>  before  the default block:
>
> case CTRL:
>                    (void) fprintf(stderr, "%s\n",
> gettext(MSG_SHELL_UNCHANGED));
>                     break;
> ****************************************************************************************************
>
> Now when we type 'passwd  -e' in the shell and when prompted for a new
> shell, we type
> Ctrl-D, the output is
>
> You have pressed #(or Ctrl-D) which is unacceptable.
> Login shell unchanged.
> ***************************************************************************************************
> Note: # in the above refers to a unwanted character
>
> I have used c == -2 because when i wanted to test what number
> corresponds to the character
> generated by pressing Ctrl-D.
>
> Here is another idea.If we could know what signal is generated when
> Ctrl-D is pressed then we can do it more easily.
>
>
> I hope this works out. I would be happier if i can work as your
> team-member also.
>
>
>
> Regards,
> Samir Kumar Mishra
> 3rd year , Electronics and Telecommunication Engg.
> UCE, Burla(India)
>

Reply via email to