RCMD

Section: Linux Programmer's Manual (3)
Updated: 2020-12-21
Index JM Home Page
 

名前

rcmd, rresvport, iruserok, ruserok, rcmd_af, rresvport_af, iruserok_af, ruserok_af - リモートコマンドにストリームを返す関数群  

書式

#include <netdb.h>   /* Or <unistd.h> on some systems */

int rcmd(char **ahost, unsigned short inport, const char *locuser,
         const char *remuser, const char *cmd, int *fd2p);

int rresvport(int *port);

int iruserok(uint32_t raddr, int superuser,
             const char *ruser, const char *luser);

int ruserok(const char *rhost, int superuser,
            const char *ruser, const char *luser);

int rcmd_af(char **ahost, unsigned short inport, const char *locuser,
            const char *remuser, const char *cmd, int *fd2p,
            sa_family_t af);

int rresvport_af(int *port, sa_family_t af);

int iruserok_af(const void *raddr, int superuser,
                const char *ruser, const char *luser, sa_family_t af);

int ruserok_af(const char *rhost, int superuser,
               const char *ruser, const char *luser, sa_family_t af);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

rcmd(), rcmd_af(), rresvport(), rresvport_af(), iruserok(), iruserok_af(), ruserok(), ruserok_af():
    Since glibc 2.19:
        _DEFAULT_SOURCE
    Glibc 2.19 and earlier:
        _BSD_SOURCE  

説明

rcmd() 関数は、スーパーユーザーがリモートマシンでコマンドを実行するために 用いられる。このとき特権ポート番号をもとにした認証スキームが 用いられる。 rresvport() 関数は、特権ポート空間のアドレスを持つソケットのファイルディスクリプターを返す。 iruserok() 関数と ruserok() 関数は、 rcmd() でサービス要求を行ったクライアントの認証を行うために サーバーが用いる関数である。 以上の 4 つの関数は、 rshd(8) サーバーによって (他の関数とともに) 利用される。  

rcmd()

rcmd() 関数は gethostbyname(3) を用いて *ahost の参照を行う。ホストが存在しない場合は -1 を返す。 見つかった場合は *ahost にホストの標準名 (standard name) をセットして、 予約されているインターネットポート inport 経由でサーバーへの接続を確立する。

接続に成功したら、インターネットドメインに存在するタイプ SOCK_STREAM のソケットが呼び出しもとに返される。 このソケットの相手側はリモートコマンドの stdin および stdout に接続される。 fd2p がゼロでない場合は、制御プロセスへの接続がもう一つ用意され、 そのファイルディスクリプターが *fd2p にセットされる。 制御プロセスはリモートコマンドからの標準エラー出力 (unit 2) を このチャンネルに返す。 また制御プロセスはこの接続から受け取ったバイトデータを UNIX シグナルの番号として扱い、リモートコマンドのプロセス グループへとシグナルを送る。 fd2p がゼロの場合は、 stderr (リモートコマンドの unit 2) は stdout と一緒にまとめられる。またこの場合はリモートプロセスへ 任意のシグナルを送ることはできなくなる。 ただし帯域外 (out-of-band) データを用いれば、 リモートプロセスの注意を引くことはできるかもしれない。

プロトコルの詳細は rshd(8) に記述されている。  

rresvport()

The rresvport() function is used to obtain a socket with a privileged port bound to it. This socket is suitable for use by rcmd() and several other functions. Privileged ports are those in the range 0 to 1023. Only a privileged process (on Linux: a process that has the CAP_NET_BIND_SERVICE capability in the user namespace governing its network namespace). is allowed to bind to a privileged port. In the glibc implementation, this function restricts its search to the ports from 512 to 1023. The port argument is value-result: the value it supplies to the call is used as the starting point for a circular search of the port range; on (successful) return, it contains the port number that was bound to.  

iruserok() と ruserok()

iruserok() と ruserok() 関数は、まず以下の引数を取る: リモートホスト (iruserok() は IP アドレスで、 ruserok() はホスト名で指定)、 2 つのユーザー名、ローカルユーザーの名前が スーパーユーザーのものであるかどうかを示すフラグ、である。 もしユーザーがスーパーユーザーではない場合は、これらの関数は /etc/hosts.equiv ファイルをチェックする。ファイルが見つからなかったり、 内容のチェックに失敗した場合には、 ローカルユーザーのホームディレクトリにある .rhosts ファイルをチェックして、サービス要求が許可されているかどうか調べる。

If this file does not exist, is not a regular file, is owned by anyone other than the user or the superuser, is writable by anyone other than the owner, or is hardlinked anywhere, the check automatically fails. Zero is returned if the machine name is listed in the hosts.equiv file, or the host and remote username are found in the .rhosts file; otherwise iruserok() and ruserok() return -1. If the local domain (as obtained from gethostname(2)) is the same as the remote domain, only the machine name need be specified.

リモートホストの IP アドレスがわかっている場合は、 ruserok() よりも iruserok()を用いる方が良いだろう。 ruserok() はリモートホストの所属するドメインの DNS サーバーが信頼できなくても 使用できるからである。  

*_af() 版

上記で述べた関数は全て IPv4 (AF_INET) ソケットで動作する。 "_af" 版では追加の引数があり、この引数でソケットアドレス ファミリーを指定できる。これらの関数では、 af 引数には AF_INETAF_INET6 が指定できる。 rcmd_af() では追加で AF_UNSPEC も指定できる。  

返り値

rcmd() 関数は成功すると有効なソケットディスクリプターを返す。 失敗すると -1 を返し、標準エラー出力に診断メッセージを 表示する。

rresvport() 関数は、成功するとバインドされた有効なソケットディスクリプターを返す。 失敗すると -1 を返し、グローバル変数 errno をエラーの原因に対応する値にセットする。 エラーコード EAGAIN は、この関数においては「すべてのネットワークポートが使用中」 という意味を表す。

ruserok() と iruserok() の返り値については、上述の説明を参照。  

バージョン

関数 iruserok_af(), rcmd_af(), rresvport_af(), ruserok_af() は glibc バージョン 2.2 以降で提供されている。  

属性

この節で使用されている用語の説明は attributes(7) を参照のこと。
Interface Attribute Value
rcmd(), rcmd_af() Thread safety MT-Unsafe
rresvport(), rresvport_af() Thread safety MT-Safe
iruserok(), ruserok(),
iruserok_af(), ruserok_af()
Thread safety MT-Safe locale

 

準拠

POSIX.1 にはない。 BSD 系、Solaris や他の多くのシステムに存在する。 これらの関数は 4.2BSD で登場した。 "_af" が付くバージョンはより最近に 追加されたもので、あまり多くのシステムには存在しない。  

バグ

iruserok() と iruserok_af() は glibc バージョン 2.12 以降のヘッダー でのみ宣言されている。  

関連項目

rlogin(1), rsh(1), rexec(3), rexecd(8), rlogind(8), rshd(8)  

この文書について

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

関連キーワード

iruserok, 関数, ruserok, rcmd, int, rresvport, リモート, RCMD, プロセス, コマンド

Linux マニュアル 一覧

[man1] [man2] [man3] [man4] [man5] [man6] [man7] [man8]
[a] [b] [c] [d] [e] [f] [g] [h] [i] [j] [k] [l] [m] [n] [o] [p] [q] [r] [s] [t] [u] [v] [w] [x] [y] [z]

 

Index

名前
書式
説明
rcmd()
rresvport()
iruserok() と ruserok()
*_af() 版
返り値
バージョン
属性
準拠
バグ
関連項目
この文書について

This document was created by man2html, using the manual pages.
Time: 12:08:35 GMT, June 11, 2022