You'd generally approach this by configuring the web server to do all of the SSL client certificate validation. SSL certificate validation is a function of the SSL session. By the time your CGI script gets the request, you've already negotiated an SSL session. If you want to know the client's distinguished name, this should be available in the SSL_CLIENT_DN environment variable. You can then do whatever necessary authorization to permit or deny the user access to functions within your script. If you're wanting to permit access to the script itself, consider doing this in the web server configuration as well. Your script can then work under the assumption that if the script is being called, the user is allowed to do so.
in reply to CGI client auth by digital certificate