chsh on Solaris

Linux & Unix newsgroup archiveUnix shell2000

Linuxmisc » Unix shell

Peter Smulder #1 / 4 Sun, 12 Mar 2000 03:00:00 GMT

Besides 'chsh' you probably also won't find 'chfn'.
Those are BSD utilities that did not make it to the POSIX
standard. In old SunOs they are there, but for some
mysterious reason they were dropped in later versions.
SGI's IRIX 5.3 has the same handicap.
--
Peter

Mohit Aro #2 / 4 Sun, 12 Mar 2000 03:00:00 GMT

Hi,
        does anyone know why there is no 'chsh' command on Solaris for
changing one's default shell. One has to ask the system administrator to change
the shell.

- Mohit

vmac.. #3 / 4 Tue, 14 Mar 2000 03:00:00 GMT

Hi,

        I have created a small C program on a Sun Solaris box running
SunOS
5.5.1. This program allows users who do not have root privileges to
change their default shells to any shell listed in "/etc/shells". The
compiled executable/binary needs to be owned by root/superuser and the
sticky bit needs to be set on.

        The file "/etc/shells" does not exist by default on SunOS 5.5.1.
You
will need to ask your UNIX administrator to create this. A sample
"/etc/shells" looks like below

/bin/sh

/bin/ksh

/bin/csh

        The C program source code follows

---------------------------------- CUT
----------------------------------------

/******************************************************************************

    This is a wrapper for "/usr/bin/passwd", with the "-e" option so

that users without root privileges can change their default shell, to a

valid shell listed in "/etc/shells".

******************************************************************************/

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

#include <pwd.h>

#include <errno.h>

main(int argc, char *argv[])

{

    uid_t this_uid;

    uid_t curr_uid;

    pid_t fork_pid;

    pid_t wait_pid;

    struct passwd *curr_passwd;

    curr_uid = getuid();

    curr_passwd = getpwuid(curr_uid);

    if (curr_passwd == NULL)

    {

        fprintf(stderr, "chsh : %s %d\n", strerror(errno), errno);

        fprintf(stderr, "chsh : Error getpwnam(%d)'.\n", curr_uid);

        exit(1);

    }

    fork_pid = fork();

    if (fork_pid)

    {

        /* IN PARENT */

        while ( (wait_pid = wait((int *) 0)) != -1 &&

                (wait_pid != fork_pid) )

        ;

    }

    else

    {

        /* IN CHILD */

        if (seteuid(0))

        {

            fprintf(stderr, "child : %s %d\n", strerror(errno), errno);

            fprintf(stderr, "child : Error seteuid(0)'.\n");

            exit(1);

        }

        if (setuid(0))

        {

            fprintf(stderr, "child : %s %d\n", strerror(errno), errno);

            fprintf(stderr, "child : Error setuid(0)'.\n");

            exit(1);

        }

        if (execl("/usr/bin/passwd", "passwd", "-e",
curr_passwd->pw_name, (char *)0))

        {

            fprintf(stderr, "chsh : %s %d\n", strerror(errno), errno);

            fprintf(stderr, "chsh : Error execl-ing 'passwd -e'.\n");

            exit(1);

        }

    }

---------------------------------- CUT
---------------------------------------

        Please let me know if you find any problems, security holes in
this

program. My email address is vmac...@edsatt.attmail.com

Thank You

Vinnie Machan

Per Dahlqvis #4 / 4 Sun, 19 Mar 2000 03:00:00 GMT

Hi,

there is.
if nis+, nispasswd -s
if nis, RTM passwd, think its "passwd -e" or something..
if files, RTM
Works fine!

--
Per Dahlqvist                           |Tele:070-5950993
Klarinettgatan 24 1tr                   |E-post:pe...@mhd.mh.se
871 61 H?rn?sand                      |Home:www.mhd.mh.se/~perad

Similar threads

This page is kept from the Linuxmisc archive of Linux and Unix newsgroups (snapshot 2019). Posts are shown as they were published, so commands, versions and addresses date from the original discussion. Linuxmisc.com now publishes a guide to online casinos in Canada.