Sponsored Content
Full Discussion: rshd control string
Top Forums Programming rshd control string Post 302381991 by migurus on Monday 21st of December 2009 04:33:59 PM
Old 12-21-2009
rshd control string

My host environment is Linux and SCO systems talking to a remote SCO box. Authentication has been configured, I can do rcmd or rsh between the systems. I am trying to use rsh facility of remote unix box and I don't want to use system call to rsh or rcmd. Instead, I am trying to open 514 port directly from my code and send a comand to it. My understaning is that to achieve that I need to form a control string in the following fashion:

Code:
 
\0local_user\0remote_user\0command\0

My program sends the string to the host, but gets nothing back.

Please see my code below. Just a note - to make sure code has no problems I targeted port 13 (time) and it worked, so I assume the problem is in the control string.

Code:
 
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <errno.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#define MAXSIZE 512
const   char    *ip_addr        = "192.168.1.2";
const   int     srvr_port       = 514;
main(int argc, char *argv[])
{
  int                   sd = 0;
  int                   rc, cnt, len, actually_sent;
  char                  msg[MAXSIZE] = "\0";
  char                  ch = '\0';
  char                  *p = NULL;
  struct sockaddr_in    saddr;
        sd = socket(AF_INET, SOCK_STREAM, 0);
        if(sd == -1)
        {
                printf("Socket descriptor not allocated\n");
                return(1);
        }
        memset(&saddr, 0, sizeof(saddr));
        saddr.sin_family        = AF_INET;
        saddr.sin_addr.s_addr   = inet_addr(ip_addr);
        saddr.sin_port          = htons(srvr_port);
        rc = connect(sd, (struct sockaddr *)&saddr, sizeof(saddr));
        if(rc == -1)
        {
                printf("connect err=%i <%s>\n", errno, sys_errlist[errno]);
                return(1);
        }
 
        sprintf(msg, "%i%s%i%s%i%s%i",
                        0,
                        "xuser",        0,
                        "xuser",        0,
                        "pwd",          0);
        len = 1 + 5 + 1 + 5 + 1 + 3 + 1;
        p = msg;
        actually_sent = cnt = 0;
        while(actually_sent < len)
        {
                rc = send(sd, p, len - actually_sent, 0);
                if(rc == -1)
                {
                        printf("send err %i <%s>\n", errno, sys_errlist[errno]);
                        return(1);
                }
                else
                {
                        actually_sent += rc;
                        p += rc;
                }
        }
        printf("sent %i bytes OK\n", actually_sent);
        cnt = ch = rc = 0;
        memset(msg, 0, sizeof(msg));
        for(    rc = recv(sd, &ch, 1, 0);
                (rc == 1 || (rc == -1 && errno == EWOULDBLOCK)) &&
                cnt < MAXSIZE - 1;
                rc = recv(sd, &ch, 1, 0))
        {
                *(msg + cnt) = ch;
                cnt++;
                printf("[%c] (%x)\n", ch, ch);
                if(ch == '\n')
                        break;
        }
        printf("rc=%i, errno=%i\n", rc, errno);
        printf("recv cnt=%i <%s>\n", cnt, msg);
        shutdown(sd, 0);
        return(0);
}

response from my program:
Code:
sent 17 bytes OK
rc=0, errno=0
recv cnt=0 <>

Again, authentication is OK, I can do rsh 192.168.1.2 -l xuser pwd no problem.

Any pointers would be appreciated.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Control the telnet

In my system , all user login are via telnet , we have control that only allow max. 300 telnet session in the system , now if I want to keep the max. no of telnet unchange (300) , but three specific users ( eg. userA , userB ,userC ) not count into this 300 session , is it possible ? for... (0 Replies)
Discussion started by: ust
0 Replies

2. UNIX for Advanced & Expert Users

New to Control-M

Hi, I am very new to Control-M . If anywone know about the global conditions in Control-M. (5 Replies)
Discussion started by: oraclenerd
5 Replies

3. UNIX for Dummies Questions & Answers

rshd vs. rexecd

Sun 5.8 Though I'd like to be using SSH, my client refuses to do so. So, I'm forced to use rsh/rexec for remote commands. My question is....when running a remote command via "rsh hostname <command>", do I need to have rexecd running, or just rshd on the remote server? Thanks in advance for... (1 Reply)
Discussion started by: jalburger
1 Replies

4. Shell Programming and Scripting

Replace any control character in the string

Need to replace any control character in the string in perl ---------- Post updated at 04:22 PM ---------- Previous update was at 03:50 PM ---------- Any help !!! Thanks in advance (2 Replies)
Discussion started by: hansini
2 Replies

5. AIX

RSH intermittent error rshd: 0826-813 Permission is denied.

I am getting an error from one node in a set with RSH setup between them, node one will connect to node two every other time (consistently), however node to connects to node one every time without problem. Here is what I am seeing, makes no sense to me. Can anyone help? sbhcprdb01<root>: rsh... (6 Replies)
Discussion started by: JodyTek
6 Replies

6. AIX

niminv and rshd error

I am trying to run niminv on my nim master to collect info from my nim clients. : / -> niminv -o invcon -a targets=<nimclient> -a location=/tmp/inventory rshd: 0826-813 Permission is denied. geninv: 0645-007 ATTENTION: gi_nim_standalone() returned an unexpected result. Return Status: FAILURE... (4 Replies)
Discussion started by: nerradr
4 Replies

7. AIX

rshd: 0826-813 Permission is denied.

Guy's I have two servers .. server1 and server2 I have configured the rshd and started the rshd demean in both servers by the below command . startsrc -t shell lssrc -t shell Service Command Description Status shell /usr/sbin/rshd rshd ... (4 Replies)
Discussion started by: Mr.AIX
4 Replies

8. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

9. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

10. SCO

Rshd requests logging

I would like to log requests to rshd on OSR 5.0.7, hopefully it is possible. Requests are coming from client Windows PCs, it all works most of the time, but few PCs are not able to do it. I am not sure where to start - do I tweak syslog.conf? Any pointers would be appreciated. (4 Replies)
Discussion started by: migurus
4 Replies
All times are GMT -4. The time now is 08:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy