Next Previous Contents

2. 프로그램의 설치및 설정

2.1 프로그램의 컴파일

현재 mod_auth_mysql의 버전은 2-20이다. 먼저 mod_auth_mysql-2_20_tar.tar를 홈페이지에서 다운로드 받는다. 적당한 디렉토리에다가 mod_auth_mysql-2_20_tar.tar의 압축을 풀고 configure를 하기전에 간단하게 README파일을 읽어본다.

이것을 apache_VERSION/src/modules/ 아래에 설치한다.

shell> ./configure --with-apache=/usr/local/apache\
                        --with-mysql=/usr/local/mysql

이렇게 해서 mod_auth_mysql이 설치될 아파치 디렉토리와 mysql의 디렉토리를 설정해주고 실행하고 곧바로 make를 한다. 아래는 make를 한 다음에 나오는 메시지이다.

+------------------------------------------------------------------+
| In order to proceed, please run the Apache configure script, and |
| add the following option:                                        |
| --activate-module=src/modules/auth_mysql/libauth_mysql.a         |
|                                                                  |
| and run make.                                                    |
+------------------------------------------------------------------+
| If you are upgrading from an earlier version of mod_auth_mysql,  |
| you would have to update your .htaccess files to reflect the     |
| changes in the directive names.  You can do that automatically   |
| by running the bundled update_htaccess_files.sh script.          |
+------------------------------------------------------------------+
| Please register this module at                                   |
| http://bourbon.netvision.net.il/mod_auth_mysql/                  |
|                                                                  |
| Thanks for using mod_auth_mysql!                                 |
+------------------------------------------------------------------+

메시지에서 보면 알수 있듯이 php3를 아파치에서 active하는것처럼 --activate-module=src/modules/auth_mysql/libauth_mysql.a 를 apache configure옵션에 추가하면 된다.

설치가 되었다면 아파치를 컴파일하기 이전에 mysql에 해당하는 디비를 추가시켜준다.

1. prompt> mysqladmin create http_auth

2. Create the auth table, e.g.:

prompt> mysql http_auth
mysql> create table mysql_auth (
    ->   username char(25),
    ->   passwd char(25),
    ->   groups char(25),
    ->   primary key (username)
    -> );

mysql> insert into mysql_auth values('skullq', password('hahaha'), 'mygroup');

이렇게 함으로써 mysql database에 http_auth라는 디비를 생성하고 mysql_auth라는 테이블을 만들고 username, passwd, groups을 만든 예이다. 마지막으로 hahaha라는 패스워드와 mygroup이라는 유저 skullq을 하나 집어넣어준다.

대부분 데이터베이스에 경험이 없는 사용자들이 겪는 실수중 하나는 데이터베이스에 접근가능한 유저의 추가부분에 있다. 아파치 웹서버는 nobody의 권한으로 실행되기 때문에 데이터베이스에 접근하기 위해서는 nobody유저에 대한 배려가 필요하다. mysql 메뉴얼에 보면 어떤 유저가 어디에서 무슨 데이터베이스를 어떤 권한에 의해서 조작할수 있는지에 대한 부분이 있으니 참고하길 바란다.

3. 아파치 컴파일
shell>./configure --prefix=/usr/local/apache \
                       --activate-module=src/modules/php3/libphp3.a \
                       --activate-module=src/modules/auth_mysql/libauth_mysql.a

를 실행하고 make와 make install을 하면 php3와 mod_auth_mysql이 포함된 아파치의 설치가 끝난다. 간단하게 아파치서버에 모듈이 포함되었는지 아는 방법은 /usr/local/apache/bin/httpd -l 을 치면 웹서버안에 포함되어 있는 모듈의 목록을 볼수 있다.

shell>./httpd -l
Compiled-in modules:
  http_core.c
  mod_env.c
  mod_log_config.c
  mod_mime.c
  mod_negotiation.c
  mod_status.c
  mod_include.c
  mod_autoindex.c
  mod_dir.c
  mod_cgi.c
  mod_asis.c
  mod_imap.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_access.c
  mod_auth.c
  mod_setenvif.c
  mod_auth_mysql.c  <--
  mod_php3.c
           

2.2 아파치의 설정

apache configure directory에 있는 access.conf를 수정한다. 참고로 Apache version 1.3.4 부터는 이전의 세개의 설정 파일로 나뉘어 져 있던 것들이 httpd.conf 하나로 통합되었다. 이 경우 httpd.conf 내에 다음 설정을 잡아 주면 된다. 만약 access.conf파일이나 srm.conf파일을 포함시키고 싶다면 httpd.conf에 추가시키는 항목이 있으니 주석처리를 풀어주면 된다.

만약 mysql 서버가 로컬서버가 아닌 다른 서버에 있고 그곳의 데이터베이스를 이용하고자 한다면

아파치의 httpd.conf파일에

Auth_MySQL_Info [host] [user] [password]

를 설정해줘야 한다.

모든 웹 페이지에 대한 인증을 하나의 데이터베이스로 사용하고자 한다면

Auth_MySQL_General_DB [database_name]

을 httpd.conf에 넣어줌으로써 .htaccess에 일일이 넣어줄 필요가 없다.

.htaccess파일의 사용예

Allow any known user to accses:

     AuthName My Company's Financial Information  -- AuthName은 ""로 묶어서 표시해준다.
     AuthType Basic
     require valid-user            -- 디비에 저장 되어 있는 사용자만 들어올수 있음.

Allow access only to specific users:

     AuthName My Company's Financial Information
     AuthType Basic
     require user johndoe devnull   -- johndoe와 devnull만이 인증을 거치고 들어올수 있음.


Allow only members of group 'executives' access the information:

     AuthName My Company's Financial Informatio
     AuthType Basic
     require group executives       -- executives그룹의 사용자만 인증후 들어올수 있음.

access.conf파일의 내용

Directory /usr/local/apache/htdocs
Options All
AllowOverride AuthConfig
Order Allow,deny
Allow from all
AuthName "mySQL mod_auth"
AuthType basic
Auth_MySQL_DB   http_auth
Auth_MySQL_Password_Table       mysql_auth
Auth_MySQL_Group_Table  mysql_auth
Auth_MySQL_Username_Field       username
Auth_MySQL_Password_Field       passwd
Auth_MySQL_Group_Field  groups
Auth_MySQL_Empty_Passwords      Off
Auth_MySQL_Encryption_Types     MySQL
Auth_MySQL_Encrypted_Passwords  On
Auth_MySQL_Scrambled_Passwords  On
Auth_MySQL      On

LIMIT GET POST
require valid-user
/LIMIT
/Directory

Auth_MySQL_DB [database_name]

httpd.conf파일 안에 인증을 하고자 하는 데이터베이스의 이름을 설정한다. ex). Auth_MySQL_DB http_auth

Auth_MySQL_Password_Table [password_table_name]

mysql에서 인증을 하고자 하는 user:password 한쌍이 들어가는 테이블에 대한 설정이다. 디폴트는 mysql_auth이다.

Auth_MySQL_Group_Table [group_table_name]

mysql에서 인증을 하고자 하는 group에 대한 테이블의 설정이다.

Auth_MySQL_Username_Field [username_field_name]

username필드의 이름을 설정한다. 디폴트는 username이다.

Auth_MySQL_Password_Field [password_field_name]

password필드의 이름을 설정한다. 디폴트는 passwd이다.

Auth_MySQL_Group_Field [group_field_name]

group필드의 이름을 설정한다. 디폴트는 groups이다.

Auth_MySQL_Empty_Passwords on:off

인증을 할때 password필드가 비어있다면 이것을 허용할것인지 하지 않을것인지에 대한것을 물어본다. 디폴트는 on이다.(패스워드 없이 유저필드만 집어넣고 접근가능)

Auth_MySQL_Encryption_Types [Plaintext, Crypt_DES, MySQL]

이곳은 암호화 타입에 관한 부분이다. 패스워드 필드부분에 대해서 mysql과 주고받을때 일반 text형식으로 할것인지 아님 DES방식으로 할것인지 mysql방식으로 서로 패스워드를 주고 받을지를 물어본다.

Auth_MySQL_Encrypted_Passwords on:off

만약 위에서 DES방식으로 할것을 선택하였다면 표준 유닉스의 DES방식의 암호화를 사용한다.(2바이트의 salt키와 11byte의 암호화된 데이터) 디폴트는 on이다.

Auth_MySQL_Scrambled_Passwords on:off

위와 마찬가지로 만약 mysql방식의 패스워드 인증을 한다면 mysql이 지원하는 password() 루틴에 의해서 암호를 변환하여 mysql로 전송한다.디폴트는 off이다.

Auth_MySQL_Non_Persistent on:off

인증후 mysql링크를 곧바로 끊어버릴지 말야아 할지를 설정해준다. (만든 사람왈 그냥 디폴트 값인 off로 놓을것을 추천하는군요)

Auth_MySQL_Authoritative on:off

mod_auth_mysql에 의한 인증이후에 다른 인증을 사용할것인지 않할것인지를 나타낸다.

Auth_MYSQL on:off

만약 이 옵션이 off되어 있다면 mod_auth_mysql은 자기 자신이 인증을 하지 않고 다른 인증방식으로 넘길것이다.(e.g. the flatfile auth module). 또 이 옵션이 on되었다면 mod_auth_mysql은 유효하다.

2.3 apache 1.3.12 버전에서 mod_auth_mysql 이 컴파일이 잘 되지 않을 경우

이글은 허문갑님께서 제공해 주신 글입니다. 감사 드립니다.

예전에 mysql과 아파치를 사용해서 인증해야 되는 경우가 있어서 여기 문서를 참조해 서 컴파일 한적이 있습니다. 근데 apache_1.3.12 이후 버전부터는 잘 안되더군요. 아마 이런 경우가 있으신분들 있을꺼 같아서 적습니다.

apache_1.3.12/src/include/alloc.h 이 파일을 복사해서

apache_1.3.X/src/include/ 넣고 컴파일 합니다.

그러니깐 잘 되더군요.

부가적으로 사용자 등급별(a,b,c,d 별로 있다는 가정하에)로 인증을 할려면 mod_auth_mysql 을 컴파일 합니다. 그러면 apache_1.3.X 방에 소스가 카피가 되죠.

/apache_1.3.X/src/modules/auth_mysql

디렉토리에 mod_auth_mysql.c 파일을 조금 수정 합니다.

query = (char *) pstrcat(r->pool, "select ", auth_password_field 
        , " from ", auth_table, " where ", auth_user_field, "='",  
        esc_user,"'", "and (member_class = 'c' or member_class = 'b'  
        or member_class   = 'a')", NULL); 

보시면 원본이랑 조금 틀리실껍니다. 뒤에 추가된 부분은 member_class 필드에 c , b , a 권한을 가진 사용자만 로그온 하라고 수정 한것입니다. -_-; 수정본만 가지고 있어서... 원본이 어떻게 되어 있는지 적지를 못했네요.. -_-a

이렇게 수정하고 컴파일 하시면 됩니다. 나중에 컴파일 문제없이 됐고 httpd.conf 파일 문제없이 수정 했고 table 도 정확 한데 인증이 잘 안되시면 꼭 apache 디렉토리안에 있는 에러 로그를 꼭 보세요. 거기에 mysql query식이 에러가 남어 있으니깐 query식을 보시고 수정 하시면 되겠죠.


Next Previous Contents