enhanced security user addition

From: Jason Brown <jason_at_persimmon.com>
Date: Thu, 11 Jul 1996 09:14:26 -0400 (EDT)

All -

I am trying to write code which replaces the passwd function so that the
superuser is not prompted for information (i.e., old and new passwords). This
information is supplied on the command line). I realize that this is not
secure, but there are times when this is necessary

                chpw username newpasswd gid

If the user is already in the enhanced database it should just change the
password. If the user is not in the datbase, then it should add them to
it setting the system required elements and then modifyind the relevent
user-specific information.

I have some source code that works well for changing information
on an existing user, but I need this to work for a _new_ user as well. The
breakdown is when I try to get a "default" entry for addition into the
enhanced security database. I have been unable to find the call that sets all
of the relevent default system required information, so that I can simply
modify the user-specific fields

        pr->ufld.fd_name pr->uflg.fg_name
        pr->ufld.fd_uid pr->uflg.fg_uid

In particular, I need to set the clearance, etc. Does anyone know how to
do this?

Thanks is advance.
----------------------------------------------------------
Jason Brown Persimmon, IT
jason_at_persimmon.com http://www.persimmon.com
4813 Emperor Blvd, Suite 130 voice: (919) 941-9339
Durham, NC 27703 fax: (919) 941-9378
----------------------------------------------------------

/*
 * Tony Prince
 * Change Protected Passwd
 *
 * chpw username oldpasswd newpasswd
 *
 * exit(0) success
 * exit(1) invalid number of parameters
 * exit(2) invalid old pass
 * exit(3) unable to change
 *
 * modified by Jason Brown
 * Persimmon IT, Inc.
 * July 9, 1996
 *
 * chpw username newpasswd gid
 *
 * return
 * 0 success
 * 1 unable to change
 */

#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/security.h>
#include <prot.h>


int main(int argc, char **argv)
{
  struct pr_passwd *pr;
  char *np;
  char salt_feed[2];
  char salt[2];
  register int i;


  /* init protected password databases */
  set_auth_parameters();
        
  /* get protected password - search by name */
  if ( !(pr = getprpwnam(argv[1])) ){

    fprintf(stderr,"Couldn't load user\nMaking one!");

    /* ------------ this part doesn't work ------------*/

    /* get a default user and modify the relevent fields */

    /* malloc room for it */
    if ( (pr = (struct pr_passwd *)malloc( sizeof(struct pr_passwd) )) ){
      memset( pr, 0, sizeof(struct pr_passwd) );
    } else {
      return 1;
    }

    /* set the system required stuff */


    /* set the user-specific stuff */
    strcpy(pr->ufld.fd_name,argv[1]); pr->uflg.fg_name=1;
    pr->ufld.fd_uid = (uid_t)(argv[3]); pr->uflg.fg_uid=1;

    /* ------------ this part doesn't work ------------*/

  }

  /* salt the crypt routine with char's from time */
  {
    time_t now=time(NULL);
    strncpy(salt_feed,ctime(&now),1);
    strncat(salt_feed,ctime(&now)+18,1);
  }

  /* get new passwd and encrypt */
  np = ( char * ) crypt(argv[2],salt_feed);
  sprintf(pr->ufld.fd_encrypt, "%s", np);
  if ( putprpwnam(argv[1],pr) == 0 ) {
    fprintf(stderr,"Error in update");
    return 1;
  }

  return 0;

}


----------------------------------------------------------
Jason Brown Persimmon, IT
jason_at_persimmon.com http://www.persimmon.com
4813 Emperor Blvd, Suite 130 voice: (919) 941-9339
Durham, NC 27703 fax: (919) 941-9378
----------------------------------------------------------
Received on Thu Jul 11 1996 - 16:08:41 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT