SUMMARY: Doing a keylogin by systemcall

From: Christian Masopust (Christian.Masopust@emndev.siemens.co.at)
Date: Tue Oct 25 1994 - 06:28:37 CDT


----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 22

Hi all!

Here's the Summary for doing a keylogin by system-calls!

There were few responses (beside that for summaries....), but
they helped!

Compile the attached program with cc -o keys keys.c -lrpcsvc -lnsl
and have fun (?) ...

Regards and thank's to all who helped.
 __^__ __^__
( ___ )----------------------------------------------------------( ___ )
 | / | Christian Masopust | \ |
 | / | | \ |
 | / | Siemens AG Austria, Program and System Engineering | \ |
 | / | A-1210 Wien, Siemensstr. 88-92 | \ |
 | / | Phone: +43-1-2501-4516 Fax: +43-1-2501-3759 | \ |
 |___| |___|
(_____)------Email: Christian.Masopust@emndev.siemens.co.at------(_____)
----------
X-Sun-Data-Type: c-file
X-Sun-Data-Description: c-file
X-Sun-Data-Name: keys.c
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 95

#include <stdlib.h>
#include <rpc/rpc.h>
#include <rpc/key_prot.h>
#include <sys/utsname.h>
#include <string.h>

char* get_key_from_passw(const char *passw)
{
   char fullname[MAXNETNAMELEN + 1];
   char secret[sizeof(keybuf) + 1];
   char *_priv_key;
   
   if (!getnetname(fullname)) return NULL;
   if (! getsecretkey(fullname, secret, passw)) return NULL;
   if (secret[0] == 0) return NULL;
   
   _priv_key = malloc (sizeof(keybuf));
   memcpy(_priv_key,secret,sizeof(keybuf));
   return _priv_key;
}

static struct timeval TIMEOUT = { 25, 0 };

keystatus *key_net_put_2(key_netstarg *argp, CLIENT *clnt)
{
        static keystatus clnt_res;

        memset((char *)&clnt_res, 0, sizeof (clnt_res));
        if (clnt_call(clnt, KEY_NET_PUT,
                (xdrproc_t) xdr_key_netstarg, (caddr_t) argp,
                (xdrproc_t) xdr_keystatus, (caddr_t) &clnt_res,
                TIMEOUT) != RPC_SUCCESS) {
                return (NULL);
        }
        return (&clnt_res);
}

int key_setnet(key_netstarg *netst)
{
   CLIENT *clnt;
   keystatus keyst;
   char * host;
   struct utsname un;
   uname(&un);
   host = un.nodename;
   clnt = clnt_create(host, KEY_PROG, KEY_VERS2, "netpath");
   if (clnt == (CLIENT *) NULL)
   {
      clnt_pcreateerror(host);
      return -1;
   }
   auth_destroy(clnt->cl_auth);
   
   clnt->cl_auth = authsys_create_default();
   
   keyst = *key_net_put_2(netst, clnt);
   clnt_destroy(clnt);

   if (keyst == 0) return 0;
   else return -1;
}

int put_key_into_keyserv(char *priv_key)
{
   char fullname[MAXNETNAMELEN + 1];
   key_netstarg netst;
   
   if (!getnetname(fullname)) return -1;
   
   netst.st_pub_key[0] = 0;
   memcpy(netst.st_priv_key,priv_key,sizeof(keybuf));
   netst.st_netname = strdup(fullname);
   
   if (key_setnet(&netst) < 0 ) return -1;
   return 0;
}

main()
{
   char *privkey;
   privkey = get_key_from_passw(getpass("Password: "));
   if (!privkey)
   {
      fprintf (stderr, "password not correct!");
      return 1;
   }
   printf ("private key: %s\n", privkey);
   printf ("result: %d\n", put_key_into_keyserv(privkey));
}
 __^__ __^__
( ___ )----------------------------------------------------------( ___ )
 | / | Christian Masopust | \ |
 | / | | \ |
 | / | Siemens AG Austria, Program and System Engineering | \ |
 | / | A-1210 Wien, Siemensstr. 88-92 | \ |
 | / | Phone: +43-1-2501-4516 Fax: +43-1-2501-3759 | \ |
 |___| |___|
(_____)------Email: Christian.Masopust@emndev.siemens.co.at------(_____)



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:09:13 CDT