Path: phoebe.st.ryukoku.ac.jp!rinsgw!rnws.ryukoku.ac.jp!cancer.nca5.ad.jp!nfeed.gw.nagoya-u.ac.jp!news.cc.nagoya-u.ac.jp!nuis!odins-suita!kuee-news!tamaru-news!Q.T.Honey!sutnews.sut.ac.jp!news.join.ad.jp!wnoc-tyo-news!aist-nara!hirosh-a From: hirosh-a@is.aist-nara.ac.jp (Hiroshi Asakura) Newsgroups: fj.sources Subject: intra_auth_1.0.patch Apache patch for authentication in Intranet Date: 27 Nov 1997 14:01:43 GMT Organization: NARA Institute of Science and Technology Lines: 127 Message-ID: <65jug7$30@fse3.aist-nara.ac.jp> NNTP-Posting-Host: sion.aist-nara.ac.jp Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP X-Newsreader: mnews [version 1.20] 1996-12/08(Sun) ============================================================================ Apache patch -- Authentication Patch in Intranet rel 1.0 -- by Asakura Hiroshi/NAIST ============================================================================ [概略] イントラネット等、内部ネットワークにおいてWWWを利用する場合、UNIXパスワード ファイルを用いて認証を行うことがあります。この場合 Apache を root 権限で 動作させることになるのですが、CGIやSSI等のことを考えると危険です。 本パッチは Apache 1.2.4 において、httpdの実効id がroot以外でも Authentication Module(/etc/passwdを使った認証)ができるようにするパッチです。 [内容] 本来、Apache 1.2.4 + Authentication Module の組合せを使用することにより Web上で/etc/passwdを使った認証を行うことが可能です。が、この場合、httpd を root 権限 (uid = 0) で起動しなければならず、非常に危険な状態でサーバを 動かすことになります。 実効id と 実id をうまく使うことにより、この危険を少しでも回避するのがこの パッチです。具体的には以下のような感じになります。 o httpd の起動は root(uid = 0) で行います。 o 起動後の httpd は httpd.conf で設定した実効uidで動作します。 o SSI, CGIなどについては httpd.conf で設定した uid で実行されます。 o mod_auth_sys (Web上での認証機能) は root権限(uid = 0) で動作します。 +--------------+-----------------------+----------------------+ | |本パッチを使用した場合 |パッチを使用しない場合| +--------------+-----------------------+----------------------+ |httpdの実効uid|httpd.confで指定したuid| *危険* root| +--------------+-----------------------+----------------------+ |cgi,ssiなど |httpd.confで指定したuid| *危険* root| +--------------+-----------------------+----------------------+ |認証時 | root| root| +--------------+-----------------------+----------------------+ [対象] o Apache_1.2.4 o mod_auth_sys (mod_auth_sys-1.2.tar.gz) このモジュールは http://pageplus.com/~hsf/sources/mod_auth_sys/ にある mod_auth_sys-1.2.tar.gz です。他にも同様のモジュールが見受けられますが それらにはパッチが正しくあたりません。 [方法] apache の src ディレクトリに mod_auth_sys.c を展開してください。そして、 src ディレクトリで patch をあててください。 --- 朝倉浩志(Asakura Hiroshi) 奈良先端科学技術大学院大学情報科学研究科情報システム学専攻 マルチメディア統合システム講座(植村研究室)博士前期課程1年 hirosh-a@is.aist-nara.ac.jp *** ../old/http_main.c Fri Aug 15 17:29:50 1997 --- http_main.c Fri Sep 26 14:33:52 1997 *************** *** 1696,1702 **** GETUSERMODE(); #else /* Only try to switch if we're running as root */ ! if (!geteuid() && setuid(user_id) == -1) { #endif log_unixerr("setuid", NULL, "unable to change uid", server_conf); exit (1); --- 1696,1702 ---- GETUSERMODE(); #else /* Only try to switch if we're running as root */ ! if (!geteuid() && seteuid(user_id) == -1) { /* by asakura */ #endif log_unixerr("setuid", NULL, "unable to change uid", server_conf); exit (1); *** ../old/util_script.c Fri Jun 27 02:28:56 1997 --- util_script.c Fri Sep 26 22:46:37 1997 *************** *** 566,571 **** --- 566,572 ---- } } #else + setreuid(geteuid(), -1); /* by asakura */ if ( suexec_enabled && ((r->server->server_uid != user_id) || (r->server->server_gid != group_id) || *** ./mod_auth_sys-1.2/mod_auth_sys.c Sat May 24 18:21:03 1997 --- mod_auth_sys.c Fri Sep 26 22:32:17 1997 *************** *** 111,119 **** return(!WEXITSTATUS(status)); #else struct passwd *ptr; ! ! if ((ptr=getpwnam(user)) == (struct passwd *)NULL) return(0); ! return(!strcmp(ptr->pw_passwd,(char *)crypt(passwd,ptr->pw_passwd))); #endif } --- 111,125 ---- return(!WEXITSTATUS(status)); #else struct passwd *ptr; ! int euid; /* by asakura */ ! euid = geteuid(); /* by asakura */ ! setreuid(-1, 0); /* by asakura */ ! if ((ptr=getpwnam(user)) == (struct passwd *)NULL) { /* by asakura */ ! setreuid(-1, euid); /* by asakura */ ! return(0); /* by asakura */ ! } /* by asakura */ ! setreuid(-1, euid); /* by asakura */ ! return(!strcmp(ptr->pw_passwd,(char *)crypt(passwd,ptr->pw_passwd))); #endif } --- 朝倉浩志(Asakura Hiroshi) 奈良先端科学技術大学院大学情報科学研究科情報システム学専攻 マルチメディア統合システム講座(植村研究室)博士前期課程1年 hirosh-a@is.aist-nara.ac.jp