1

CネットワークアプリケーションのユーザーをPAMで認証したいのですが、ここStackでPAMの良い例を見つけました。これを下部に添付します。問題は、私の開発マシンに、PAMが使用するように設定されている指紋リーダーがあることです/etc/pam.d/common-auth

#%PAM-1.0                                                                                                                                                                                                                        
#                                                                                                                                                                                                                                
# This file is autogenerated by pam-config. All changes                                                                                                                                                                          
# will be overwritten.                                                                                                                                                                                                           
#                                                                                                                                                                                                                                
# Authentication-related modules common to all services                                                                                                                                                                          
#                                                                                                                                                                                                                                
# This file is included from other service-specific PAM config files,                                                                                                                                                            
# and should contain a list of the authentication modules that define                                                                                                                                                            
# the central authentication scheme for use on the system                                                                                                                                                                        
# (e.g., /etc/shadow, LDAP, Kerberos, etc.). The default is to use the                                                                                                                                                           
# traditional Unix authentication mechanisms.                                                                                                                                                                                    
#                                                                                                                                                                                                                                
auth    required    pam_env.so                                                                                                                                                                                                 
auth    sufficient  pam_fprint.so                                                                                                                                                                                             
auth    optional    pam_gnome_keyring.so                                                                                                                                                                                         
auth    required    pam_unix2.so

pam_fprint.so指紋リーダープラグインです。通常ログインすると、スキャンが失敗する可能性があり、パスワードの入力を求められます。/etc/pam.d/sshdただし、sshdデーモンはフィンガープリントをまったく開始しません。たとえば、common-authモジュールを参照するため、フィンガープリントをプルする必要があるため、フィンガープリントをスキップする方法を理解したいと思います。

#%PAM-1.0
auth     requisite  pam_nologin.so
auth     include        common-auth
account  requisite      pam_nologin.so
account  include        common-account
password include        common-password
session  required   pam_loginuid.so
session  include        common-session
session  optional       pam_lastlog.so   silent noupdate showfailed

Cプログラムから「sshd」スキームを参照しようとしましたが、それでも指紋リーダーが起動します。どういうわけかCで指紋リーダーをスキップし、指紋リーダーのデフォルト構成を保持したいと思います。

    #include <stdlib.h>
    #include <iostream>
    #include <fstream>
    #include <security/pam_appl.h>
    #include <unistd.h>

// To build this:
// g++ test.cpp -lpam -o test

struct pam_response *reply;

//function used to get user input
int function_conversation(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
{
  *resp = reply;
  return PAM_SUCCESS;
}

int main(int argc, char** argv)
{
  if(argc != 2) {
      fprintf(stderr, "Usage: check_user <username>\n");
      exit(1);
  }
  const char *username;
  username = argv[1];

  const struct pam_conv local_conversation = { function_conversation, NULL };
  pam_handle_t *local_auth_handle = NULL; // this gets set by pam_start

  int retval;

  // local_auth_handle gets set based on the service
  retval = pam_start("common-auth", username, &local_conversation, &local_auth_handle);

  if (retval != PAM_SUCCESS)
  {
    std::cout << "pam_start returned " << retval << std::endl;
    exit(retval);
  }

  reply = (struct pam_response *)malloc(sizeof(struct pam_response));

  // *** Get the password by any method, or maybe it was passed into this function.
  reply[0].resp = getpass("Password: ");
  reply[0].resp_retcode = 0;

  retval = pam_authenticate(local_auth_handle, 0);

  if (retval != PAM_SUCCESS)
  {
    if (retval == PAM_AUTH_ERR)
    {
      std::cout << "Authentication failure." << std::endl;
    }
    else
    {
      std::cout << "pam_authenticate returned " << retval << std::endl;
    }
    exit(retval);
  }

  std::cout << "Authenticated." << std::endl;

  retval = pam_end(local_auth_handle, retval);

  if (retval != PAM_SUCCESS)
  {
    std::cout << "pam_end returned " << retval << std::endl;
    exit(retval);
  }

  return retval;
}
4

1 に答える 1

1

sshdが実際にそのモジュールをスキップしているとは思えません。むしろ、指紋リーダー認証モジュールは(賢明に)認証ユーザーがローカルシステム上にいるように見えるか、ネットワーク経由でアクセスしているように見えるか(PAMデータから把握できます)をチェックしており、これがrhostあれば何もしません。ネットワーク認証です。ソースコードを見てそのようなテストがあるかどうかを確認するか、PAM_RHOST経由pam_set_itemで設定して動作が変わるかどうかを確認してみてください。

実際の質問に答えるために、1つのモジュールを除いて特定のPAMグループを実行するようにPAMに指示する方法はないと思います。実行したいことを実行するための予想される方法は、/etc/pam.d渡したアプリケーション名に一致する新しい構成ファイルを作成することです。このファイルには、実行するモジュールのみが含まれていますが、含まれpam_startていません。common-auth

于 2013-03-17T06:42:11.737 に答える