/usr/share/doc/HOWTO/ja-html/Virtual-Services-HOWTO-3.html is in doc-linux-ja-html 2006.05.25-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>Virtual Services Howto: ¥Ð¡¼¥Á¥ã¥ë¥Ç¡¼¥â¥ó(virtuald)</TITLE>
<LINK HREF="Virtual-Services-HOWTO-4.html" REL=next>
<LINK HREF="Virtual-Services-HOWTO-2.html" REL=previous>
<LINK HREF="Virtual-Services-HOWTO.html#toc3" REL=contents>
</HEAD>
<BODY>
<A HREF="Virtual-Services-HOWTO-4.html">¼¡¤Î¥Ú¡¼¥¸</A>
<A HREF="Virtual-Services-HOWTO-2.html">Á°¤Î¥Ú¡¼¥¸</A>
<A HREF="Virtual-Services-HOWTO.html#toc3">Ìܼ¡¤Ø</A>
<HR>
<H2><A NAME="s3">3. ¥Ð¡¼¥Á¥ã¥ë¥Ç¡¼¥â¥ó(virtuald)</A></H2>
<H2><A NAME="ss3.1">3.1 ¤É¤Î¤è¤¦¤ÊÆ°ºî¤ò¤¹¤ë¤«</A>
</H2>
<P>¥Í¥Ã¥È¥ï¡¼¥¯Àܳ¤Ï"IP¥¢¥É¥ì¥¹"¤È"¥Ý¡¼¥ÈÈÖ¹æ"¤Î¥Ú¥¢
¤«¤é¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¥Í¥Ã¥È¥ï¡¼¥¯¥×¥í¥°¥é¥ß¥ó¥°¤ÎAPI(Applications Program
Interface)¤Ï<CODE>sockets api</CODE>¤È¸Æ¤Ð¤ì¤Þ¤¹¡£¥½¥±¥Ã¥È¤Ï³«¤¤¤¿¥Õ¥¡¥¤¥ë¤Î¤è¤¦¤Ë
¿¶Éñ¤¤¡¢¤³¤ì¤ËÂФ¹¤ëÆɤ߽ñ¤¤ò¤¹¤ë¤³¤È¤Ç¥Í¥Ã¥È¥ï¡¼¥¯·Ðͳ¤Ç¥Ç¡¼¥¿¤ò¤ä¤ê¤È¤ê
¤¬¤Ç¤¤Þ¤¹¡£
<P>¥í¡¼¥«¥ë¥½¥±¥Ã¥È¤ÎIP¥¢¥É¥ì¥¹¤òÊÖ¤¹¥Õ¥¡¥ó¥¯¥·¥ç¥ó¥³¡¼¥ë<CODE>getsockname</CODE>
¤¬¤¢¤ê¤Þ¤¹¡£
<P>virtuald¤Ï<CODE>getsockname</CODE>(ÌõÃí¡§<CODE>/lib/libc.so</CODE>)¤ò¡¢
¤É¤Î¥í¡¼¥«¥ë¥Þ¥·¥ó¤ÎIP¤¬¥¢¥¯¥»¥¹¤µ¤ì¤Æ¤¤¤ë¤«¤ò·è¤á¤ë¤Î¤ËÍѤ¤¤Þ¤¹¡£
Virtuald¤ÏÀßÄê¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ß¡¢¤½¤ÎIP¤ËÂбþ¤¹¤ë¥Ç¥£¥ì¥¯¥È¥ê¤ò¼èÆÀ¤·¤Þ¤¹¡£
¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë <CODE>chroot</CODE>¤·¤¿¸å¡¢¼ÂºÝ¤Ë¹Ô¤ï¤ì¤ë¥µ¡¼¥Ó¥¹¤ËÀܳ¤ò
°ú¤ÅϤ·¤Þ¤¹¡£
<P><CODE> chroot </CODE> ¤Ï¥ë¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê'/' ¤òÊ̤Υǥ£¥ì¥¯¥È¥ê¤Ë¥»¥Ã¥È
¤·Ä¾¤·¡¢¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê(¿·¤·¤¤¥ë¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê)¤è¤ê¤â¾å¤Ë¤¢¤ëÁ´¤Æ¤Î¤â¤Î
¤Ï¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Þ¤»¤ó(ÀÚ¤êÎ¥¤µ¤ì¤Þ¤¹)¡£
¤³¤¦¤·¤Æ³ÆIP¥¢¥É¥ì¥¹¤Ï¤½¤ì¤¾¤ì¤Î²¾ÁÛ¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤ò¼èÆÀ¤·¤Þ¤¹¡£
¤³¤ì¤Ï¥Í¥Ã¥È¥ï¡¼¥¯¥×¥í¥°¥é¥à¤«¤é¤ÏÆ©²áŪ¤Ê¤Î¤Ç(¾å¤Ë½ñ¤¤¤¿¤è¤¦¤ÊÁàºî¤Ï
±£¤·¤Æ¤¢¤ë¤Î¤Ç)¡¢¥×¥í¥°¥é¥à¤Ï²¿»ö¤â¤Ê¤«¤Ã¤¿¤«¤Î¤è¤¦¤ËÆ°ºî¤·¤Þ¤¹¡£
<P>¤³¤Î¤è¤¦¤Ë¤·¤Æ¡¢inetd¤È¤¤¤Ã¤¿¥×¥í¥°¥é¥à¤ÈÏ¢·ë¤µ¤ì¤¿Virtuald
¤Ï¤¤¤í¤¤¤í¤Ê¥µ¡¼¥Ó¥¹¤ò²¾ÁÛ²½¤·¤Æ»È¤¦¤³¤È¤¬¤Ç¤¤ë¤Î¤Ç¤¹¡£
<P>
<H2><A NAME="ss3.2">3.2 inetd </A>
</H2>
<P>Inetd¤ÏÊ£¿ô¤Î¥Ý¡¼¥È¤ò´Æ»ë¤·¡¢Àܳ¤¬¤¢¤Ã¤¿¾ì¹ç¤Ë(Î㤨¤ÐpopÍ׵᤬¤¢¤Ã¤¿¤È¤
¤Ê¤É¤Ë)¥Í¥Ã¥È¥ï¡¼¥¯¥Í¥´¥·¥¨¡¼¥·¥ç¥ó¹Ô¤Ã¤Æ»ØÄꤵ¤ì¤¿¥×¥í¥°¥é¥à¤ËÀܳ¤ò
°ú¤ÅϤ¹¥¹¡¼¥Ñ¡¼¥µ¡¼¥Ð¤Ç¤¹¡£
¤³¤ì¤Ë¤è¤ê¡¢É¬Íפ¬¤Ê¤¯¤Æ²¿¤â¤·¤Æ¤¤¤Ê¤¤¥µ¡¼¥Ð¤¬¤Ê¤¤¤è¤¦¤Ë¤·¤Þ¤¹¡£
<P>ɸ½àŪ¤Ê <CODE>/etc/inetd.conf</CODE>¥Õ¥¡¥¤¥ë¤Ï
<PRE>
ftp stream tcp nowait root /usr/sbin/tcpd wu.ftpd -l -a
pop-3 stream tcp nowait root /usr/sbin/tcpd in.qpop -s
</PRE>
¤È¤Ê¤ê¤Þ¤¹¡£(<EM>ÌõÃí¡§</EM>pop-3¤Ïpop3¤Î¾ì¹ç¤Ïpop3¤Ë¤·¤Æ²¼¤µ¤¤)¡£
<P>
<P>¤Þ¤¿²¾ÁÛŪ¤Ê<CODE>/etc/inetd.conf</CODE>¥Õ¥¡¥¤¥ë¤Ï
<PRE>
ftp stream tcp nowait root /usr/bin/virtuald virtuald /virtual/conf.ftp wu.ftpd -l -a
pop-3 stream tcp nowait root /usr/bin/virtuald virtuald /virtual/conf.pop in.qpop -s
</PRE>
¤È¤Ê¤ê¤Þ¤¹¡£
<P>
<P>
<H2><A NAME="ss3.3">3.3 virtual.conf</A>
</H2>
<P>¤½¤ì¤¾¤ì¤Î¥µ¡¼¥Ó¥¹¤ËÂбþ¤¹¤ëIP¤È¥Ç¥£¥ì¥¯¥È¥ê¤ò¥³¥ó¥È¥í¡¼¥ë¤¹¤ë
conf¥Õ¥¡¥¤¥ë¤ò¼èÆÀ¤·¤Þ¤¹¡£°ì¤Ä¤Î¥Þ¥¹¥¿¡¼conf¥Õ¥¡¥¤¥ë¤¬¤¢¤ê¡¢¤Þ¤¿
¥É¥á¥¤¥ó¤Î°Û¤Ê¤ë¥ê¥¹¥È¤Î¥µ¡¼¥Ó¥¹¤¬É¬ÍפʤȤ¤Ï¤½¤ì¤Ë±þ¤¸¤¿conf¥Õ¥¡¥¤¥ë
¤òÍÑ°Õ¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£virtual.conf¤Ï°Ê²¼¤Î¤è¤¦¤ÊÆâÍƤǤ¹¡£
<PRE>
# This is a comment and so are blank lines
# Format IP <SPACE> dir <NOSPACES>
10.10.10.129 /virtual/foo.bar.com
10.10.10.130 /virtual/bar.foo.com
10.10.10.157 /virtual/boo.la.com
</PRE>
(<EM>ÌõÃí¡§</EM>¼ÂºÝ¤ÎÃæ¿È¤Ï³ÆÀßÄê´Ä¶¤Ë¹ç¤ï¤»¤Æ½ñ¤´¹¤¨¤Æ²¼¤µ¤¤¡£
¤½¤·¤Æ¤³¤Î¥Õ¥¡¥¤¥ë¤Ï(¾å¤Îinitd.conf¤ÎÀßÄê¤Ë¹ç¤ï¤»¤¿)³ºÅö¥Ç¥£¥ì¥¯¥È¥ê
¤ª¤è¤Ó¥Õ¥¡¥¤¥ë̾¤Ë¥³¥Ô¡¼¤·¤Þ¤¹)¡£
<P>
<H2><A NAME="ss3.4">3.4 virtuald¤Î¥½¡¼¥¹</A>
</H2>
<P>(<EM>ÌõÃí¡§</EM>¤³¤ÎVirtuald¤Î¥½¡¼¥¹¤Ï <CODE>gcc -o viturald virtuald.c</CODE>¤È¤·¤Æ
¥³¥ó¥Ñ¥¤¥ë¤Ç¤¤Þ¤¹¡£¤Þ¤¿¸å¤Îʸ¾Ï¤È¹ç¤ï¤»¤ë¤¿¤á¤Ë<CODE>/usr/bin</CODE>¤Ë
¥³¥Ô¡¼¤·¤Þ¤¹)
<HR>
<PRE>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <string.h>
#include <syslog.h>
#include <stdio.h>
#define BUFSIZE 8192
main(int argc,char **argv)
{
char buffer[BUFSIZE];
char *ipaddr,*dir;
logit("Virtuald Starting: $Revision: 1.2 $");
if (!argv[1])
{
logit("invalid arguments: no conf file");
quitting_virtuald(0);
}
if (!argv[2])
{
logit("invalid arguments: no program to run");
quitting_virtuald(0);
}
if (getipaddr(&ipaddr))
{
logit("getipaddr failed");
quitting_virtuald(0);
}
sprintf(buffer,"Incoming ip: %s",ipaddr);
logit(buffer);
if (iptodir(&dir,ipaddr,argv[1]))
{
logit("iptodir failed");
quitting_virtuald(0);
}
if (chroot(dir)<0)
{
logit("chroot failed: %m");
quitting_virtuald(0);
}
sprintf(buffer,"Chroot dir: %s",dir);
logit(buffer);
if (chdir("/")<0)
{
logit("chdir failed: %m");
quitting_virtuald(0);
}
if (execvp(argv[2],argv+2)<0)
{
logit("execvp failed: %m");
quitting_virtuald(0);
}
}
int logit(char *buf)
{
openlog("virtuald",LOG_PID,LOG_DAEMON);
syslog(LOG_ERR,buf);
closelog();
return 0;
}
int quitting_virtuald(int retval)
{
exit(retval);
return 0;
}
int getipaddr(char **ipaddr)
{
struct sockaddr_in virtual_addr;
static char ipaddrbuf[BUFSIZE];
int virtual_len;
char *ipptr;
virtual_len=sizeof(virtual_addr);
if (getsockname(0,(struct sockaddr *)&virtual_addr,&virtual_len)<0)
{
logit("getipaddr: getsockname failed: %m");
return -1;
}
if (!(ipptr=inet_ntoa(virtual_addr.sin_addr)))
{
logit("getipaddr: inet_ntoa failed: %m");
return -1;
}
strncpy(ipaddrbuf,ipptr,sizeof(ipaddrbuf)-1);
*ipaddr=ipaddrbuf;
return 0;
}
int iptodir(char **dir,char *ipaddr,char *filename)
{
char buffer[BUFSIZE],*bufptr;
static char dirbuf[BUFSIZE];
FILE *fp;
if (!(fp=fopen(filename,"r")))
{
logit("iptodir: fopen failed: %m");
return -1;
}
*dir=NULL;
while(fgets(buffer,BUFSIZE,fp))
{
buffer[strlen(buffer)-1]=0;
if (*buffer=='#' || *buffer==0)
continue;
if (!(bufptr=strchr(buffer,' ')))
{
logit("iptodir: strchr failed");
return -1;
}
*bufptr++=0;
if (!strcmp(buffer,ipaddr))
{
strncpy(dirbuf,bufptr,sizeof(dirbuf)-1);
*dir=dirbuf;
break;
}
}
if (fclose(fp)==EOF)
{
logit("iptodir: fclose failed: %m");
return -1;
}
if (!*dir)
{
logit("iptodir: ip not found in conf file");
return -1;
}
return 0;
}
</PRE>
<HR>
<P>
<P>
<HR>
<A HREF="Virtual-Services-HOWTO-4.html">¼¡¤Î¥Ú¡¼¥¸</A>
<A HREF="Virtual-Services-HOWTO-2.html">Á°¤Î¥Ú¡¼¥¸</A>
<A HREF="Virtual-Services-HOWTO.html#toc3">Ìܼ¡¤Ø</A>
</BODY>
</HTML>
|