SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
Building Apache Modules



Marian HackMan Marinov       E-Mail: mm@1h.com
Founder and CEO of 1H Ltd.   Jabber: hackman@jabber.org
Apache architecture



➢ Request handling
➢ Memory handling
➢ Module architecture
Request handling
1. Just after reading the request (no parsing has been done)
2. Resolve the file name that this URI is trying to access
3. Parse the headers
4. Check access (allow/deny IP/Net/Host)
5. Check the authentication
6. Only if authenticated
7. Check and set the request MIME type
8. Generic fixups
9. Check which (module)function will handle the request
10. Do something before the actual log is called
Request handling
Apache 2.x has two additional hooks:
➢ map_to_storage – runs just before the header
  parser
  ➢ Reads the per-directory configuration
➢ insert_filter – runs just before the handlers
  ➢ Insert content filter
Apache memory pools
➢ Apache allocate memory on pools, which are shared
    across all modules within the same child
    process/thread.
➢ malloc/free is handled by Apache
➢ configuration is copied across all child processes
➢ misbehaving modules within Apache(mod_php)
➢ Apache common functions
    ➢ Apache 1.3 - palloc()
    ➢ Apaceh 2.x – palloc(), string handling
➢
Module architecture



➢ Options table
➢ Access table
➢ Authentication table
➢ Handlers table
How to start

➢ mod_example
  ➢ Apache 1.3
    src/modules/example/mod_example.c
  ➢ Apache 2.x
    modules/experimental/mod_example.c
➢ Include files
Structure of a module



➢ Includes
➢ Module name
➢ Module definition
➢ Module commands (options)
➢ Module configuration
Includes
➢ httpd.h - the main include (consider it as, stdio.h)
  ➢ conn_rec, server_rec, request_rec, apache common
    functions
➢ http_config.h - configuration
  ➢ module command definitions
  ➢ additional functions related to the apache
    configuration
➢ http_request.h - request handling functions
➢ http_protocol.h - low level direct manipulation of
 the request
Includes
➢ http_core.h - this file gives you everything that is
  actually provided by mod_core
➢ http_main.h - apache server handling
➢ http_log.h - logging facilities
  ➢ For Apache 2.0 and 2.2
     ➢ some apache common functions are moved in apr_strings.h
     ➢ in order to use the request and protocol functionality you would
       need also http_connection.h
     ➢ if you need server implementation functions you need ap_mpm.h
➢ These are not all includes that you may need in your
  modules
Module names


#ifdef APACHE2
module AP_MODULE_DECLARE_DATA
example_module;
#else
module MODULE_VAR_EXPORT example_module;
#endif
Module definition



➢ Apache 1.3
➢ Apache 2.x
Apache 1.3
module MODULE_VAR_EXPORT example_module = {
 STANDARD_MODULE_STUFF,
 NULL, /* module initializer */
 NULL, /* per-directory config creator */
 NULL, /* dir config merger */
 NULL, /* server config creator */
 NULL, /* server config merger */
 NULL, /* command table */
 NULL, /* [9] list of handlers */
 NULL, /* [2] filename-to-URI translation */
 NULL, /* [5] check/validate user_id */
Apache 1.3
     NULL, /* [6] check user_id is valid *here* */
     NULL, /* [4] check access by host address */
     NULL, /* [7] MIME type checker/setter */
     NULL, /* [8] fixups */
     NULL, /* [10] logger */
     NULL, /* [3] header parser */
     NULL, /* process initializer */
     NULL, /* process exit/cleanup */
     NULL /* [1] post read_request handling */
};
Apache 2.x
module AP_MODULE_DECLARE_DATA example_module = {
     STANDARD20_MODULE_STUFF,
     NULL, /* per-directory config creator */
     NULL, /* dir config merger */
     NULL, /* server config creator */
     NULL, /* server config merger */
     NULL, /* command table */
     NULL, /* set up other request processing hooks */
};


static void register_hooks(apr_pool_t *p) {
     static const char * const aszPost[] = { "mod_setenvif.c", NULL };
     /* 19 different processing hooks available */
}
Module initialization
➢ Apache 1.3
  ➢ startup and live
  ➢ the function is called two times
➢ Apache 2.0/2.2 module structure
  ➢ pre-config
  ➢ post-config
Creating new configuration
            directives


➢ Define them in the module configuration
 structure
➢ Define new module commands(options)
➢ Create functions to actually set the options,
 when found in the config
Module configuration structure

typedef struct {
     double        dummy_double;
     int           dummy_int;
     char          *dummy_char;
     array_header *dummy_array;
} example_conf;
Array handling
struct ip_range *net;
char *proxies[] = IP_RANGES;
pool *p;
conf->nets = ap_make_array(p, IP_RANGES_COUNT,
                                        sizeof(struct ip_range));
for (i = 0; i < IP_RANGES_COUNT; i++) {
    net = (struct ip_range *) ap_push_array(conf->nets);
    parse_ip( p, proxies[ i ], net );
}
Module commands(options)
➢ Apache 1.3
static const command_rec example_cmds[] = {
     {
          "Example",
          cmd_example,
          NULL,        /* argument to include in call */
          OR_OPTIONS,
          NO_ARGS,
          "Example directive - no arguments"
     },
     {NULL}
};
Module commands(options)
➢ Apache 2.x
static const command_rec x_cmds[] = {
     AP_INIT_NO_ARGS(
          "Example",
          cmd_example,
          NULL,        /* argument to include in call */
          OR_OPTIONS,
          "Example directive - no arguments"
     ),
     {NULL}
};
Possible arguments
➢ FLAG        => One of 'On' or 'Off'
➢ NO_ARGS     => No args at all, e.g. </Directory>
➢ RAW_ARGS => cmd_func parses command line itself
➢ TAKE1       => one argument only
➢ TAKE2       => two arguments only
➢ ITERATE     => one argument, occuring multiple times
➢ ITERATE2    => two arguments, 2nd occurs multiple times
➢ TAKE12      => one or two arguments
➢ TAKE3       => three arguments only
➢ TAKE23      => two or three arguments
➢ TAKE123     => one, two or three arguments
➢ TAKE13      => one or three arguments
Allowed locations for
        configuration directives
➢ RSRC_CONF      => *.conf outside <Directory> or <Location>
➢ ACCESS_CONF => *.conf inside <Directory> or <Location>
➢ OR_AUTHCFG) => *.conf inside <Directory> or <Location>
                and .htaccess when AllowOverride AuthConfig
➢ OR_LIMIT)      => *.conf inside <Directory> or <Location>
                and .htaccess when AllowOverride Limit
➢ OR_OPTIONS) => *.conf anywhere
                and .htaccess when AllowOverride Options
➢ OR_FILEINFO) => *.conf anywhere
                and .htaccess when AllowOverride FileInfo
➢ OR_INDEXES) => *.conf anywhere
                and .htaccess when AllowOverride Indexes
Module command handlers
static const char *set_examplecmd(cmd_parms *cmd, void *vconf, char *arg) {
      example_conf *conf = (example_conf *) vconf;
      if (cmd->path == NULL) {
            conf = (example_conf *)
                  ap_get_module_config(cmd->server->module_config, &example_module);
#ifdef DEBUG_OPTIONS
            fprintf(stderr, "mod_example: (%s:%d)Example (server)n",
                   cmd->config_file->name, cmd->config_file->line_number);
      } else {
            fprintf(stderr, "mod_example: (%s:%d)RelaxPerms (dir)n",
                   cmd->config_file->name, cmd->config_file->line_number);
#endif
      }
   conf->dummy_char = ap_pstrdup(cmd->pool, arg);
   return NULL;
}
Handling configuration directives



➢ Global vs. Vhost configuration
➢ Per directory/files/location
➢ Merge of the global and per-vhost configuration
➢ Initialization of the configuration
Logging
➢ ap_log_error(APLOG_MARK, APLOG_INFO,
                                 r->server, "Some string");
➢ ap_log_rerror(APLOG_MARK, APLOG_INFO,
                                 r, "Some string");
 ➢ Apache 2.x
    ➢ Added ap_log_cerror() for conn_rec handling
    ➢ Added ap_log_perror() for everything that is not server,
      record or connection related
    ➢ Added status code between the server and level
Writing portable modules
➢ Porting tricks
  #ifndef APACHE_RELEASE
  #define APACHE2
  #endif


➢ Apache common functions
  ➢ ap_palloc(1.3) -> apr_palloc(2.x)
Additional resources
http://httpd.apache.org/docs/2.2/developer/
Thank you




??? Questions ???

     Thank you

Contenu connexe

Tendances

Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with AugeasPuppet
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 
How PHP Works ?
How PHP Works ?How PHP Works ?
How PHP Works ?Ravi Raj
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0bcoca
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017Jumping Bean
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Alex S
 
Node.js basics
Node.js basicsNode.js basics
Node.js basicsBen Lin
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Puppet
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetOmar Reygaert
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7julien pauli
 

Tendances (20)

PHP 7 new engine
PHP 7 new enginePHP 7 new engine
PHP 7 new engine
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
 
Sah
SahSah
Sah
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
How PHP Works ?
How PHP Works ?How PHP Works ?
How PHP Works ?
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
Sahul
SahulSahul
Sahul
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7
 

Similaire à Building apache modules

Odoo command line interface
Odoo command line interfaceOdoo command line interface
Odoo command line interfaceJalal Zahid
 
Introduction to Apache Mesos
Introduction to Apache MesosIntroduction to Apache Mesos
Introduction to Apache MesosJoe Stein
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bChereCheek752
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing DaeHyung Lee
 
Apache2 BootCamp : Getting Started With Apache
Apache2 BootCamp : Getting Started With ApacheApache2 BootCamp : Getting Started With Apache
Apache2 BootCamp : Getting Started With ApacheWildan Maulana
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh thingsMarcus Deglos
 
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...Nagios
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfOrtus Solutions, Corp
 
Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Trygve Vea
 
GopherCon IL 2020 - Web Application Profiling 101
GopherCon IL 2020 - Web Application Profiling 101GopherCon IL 2020 - Web Application Profiling 101
GopherCon IL 2020 - Web Application Profiling 101yinonavraham
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 
Advfs system calls & kernel interfaces
Advfs system calls & kernel interfacesAdvfs system calls & kernel interfaces
Advfs system calls & kernel interfacesJustin Goldberg
 
SELinux Kernel Internals and Architecture - FOSS.IN/2005
SELinux Kernel Internals and Architecture - FOSS.IN/2005SELinux Kernel Internals and Architecture - FOSS.IN/2005
SELinux Kernel Internals and Architecture - FOSS.IN/2005James Morris
 
Tips
TipsTips
Tipsmclee
 

Similaire à Building apache modules (20)

Odoo command line interface
Odoo command line interfaceOdoo command line interface
Odoo command line interface
 
Apache Cheat Sheet
Apache Cheat SheetApache Cheat Sheet
Apache Cheat Sheet
 
Apache Hacks
Apache HacksApache Hacks
Apache Hacks
 
Introduction to Apache Mesos
Introduction to Apache MesosIntroduction to Apache Mesos
Introduction to Apache Mesos
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing
 
Apache2 BootCamp : Getting Started With Apache
Apache2 BootCamp : Getting Started With ApacheApache2 BootCamp : Getting Started With Apache
Apache2 BootCamp : Getting Started With Apache
 
TO Hack an ASP .NET website?
TO Hack an ASP .NET website?  TO Hack an ASP .NET website?
TO Hack an ASP .NET website?
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh things
 
Hack ASP.NET website
Hack ASP.NET websiteHack ASP.NET website
Hack ASP.NET website
 
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
 
Unix kernal
Unix kernalUnix kernal
Unix kernal
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
 
Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!
 
GopherCon IL 2020 - Web Application Profiling 101
GopherCon IL 2020 - Web Application Profiling 101GopherCon IL 2020 - Web Application Profiling 101
GopherCon IL 2020 - Web Application Profiling 101
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Advfs system calls & kernel interfaces
Advfs system calls & kernel interfacesAdvfs system calls & kernel interfaces
Advfs system calls & kernel interfaces
 
SELinux Kernel Internals and Architecture - FOSS.IN/2005
SELinux Kernel Internals and Architecture - FOSS.IN/2005SELinux Kernel Internals and Architecture - FOSS.IN/2005
SELinux Kernel Internals and Architecture - FOSS.IN/2005
 
Tips
TipsTips
Tips
 

Plus de Marian Marinov

Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingMarian Marinov
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsMarian Marinov
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Marian Marinov
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDBMarian Marinov
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMarian Marinov
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfMarian Marinov
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home eraMarian Marinov
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefsMarian Marinov
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd Marian Marinov
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storageMarian Marinov
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Marian Marinov
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL serverMarian Marinov
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKMarian Marinov
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networksMarian Marinov
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automationMarian Marinov
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingMarian Marinov
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of serversMarian Marinov
 
Let's Encrypt failures
Let's Encrypt failuresLet's Encrypt failures
Let's Encrypt failuresMarian Marinov
 

Plus de Marian Marinov (20)

Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & Logging
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanisms
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDB
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdf
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home era
 
Managing sysadmins
Managing sysadminsManaging sysadmins
Managing sysadmins
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefs
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storage
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL server
 
Sysadmin vs. dev ops
Sysadmin vs. dev opsSysadmin vs. dev ops
Sysadmin vs. dev ops
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDK
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networks
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automation
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel tracking
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of servers
 
Let's Encrypt failures
Let's Encrypt failuresLet's Encrypt failures
Let's Encrypt failures
 

Dernier

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Building apache modules

  • 1. Building Apache Modules Marian HackMan Marinov E-Mail: mm@1h.com Founder and CEO of 1H Ltd. Jabber: hackman@jabber.org
  • 2. Apache architecture ➢ Request handling ➢ Memory handling ➢ Module architecture
  • 3. Request handling 1. Just after reading the request (no parsing has been done) 2. Resolve the file name that this URI is trying to access 3. Parse the headers 4. Check access (allow/deny IP/Net/Host) 5. Check the authentication 6. Only if authenticated 7. Check and set the request MIME type 8. Generic fixups 9. Check which (module)function will handle the request 10. Do something before the actual log is called
  • 4. Request handling Apache 2.x has two additional hooks: ➢ map_to_storage – runs just before the header parser ➢ Reads the per-directory configuration ➢ insert_filter – runs just before the handlers ➢ Insert content filter
  • 5. Apache memory pools ➢ Apache allocate memory on pools, which are shared across all modules within the same child process/thread. ➢ malloc/free is handled by Apache ➢ configuration is copied across all child processes ➢ misbehaving modules within Apache(mod_php) ➢ Apache common functions ➢ Apache 1.3 - palloc() ➢ Apaceh 2.x – palloc(), string handling ➢
  • 6. Module architecture ➢ Options table ➢ Access table ➢ Authentication table ➢ Handlers table
  • 7. How to start ➢ mod_example ➢ Apache 1.3 src/modules/example/mod_example.c ➢ Apache 2.x modules/experimental/mod_example.c ➢ Include files
  • 8. Structure of a module ➢ Includes ➢ Module name ➢ Module definition ➢ Module commands (options) ➢ Module configuration
  • 9. Includes ➢ httpd.h - the main include (consider it as, stdio.h) ➢ conn_rec, server_rec, request_rec, apache common functions ➢ http_config.h - configuration ➢ module command definitions ➢ additional functions related to the apache configuration ➢ http_request.h - request handling functions ➢ http_protocol.h - low level direct manipulation of the request
  • 10. Includes ➢ http_core.h - this file gives you everything that is actually provided by mod_core ➢ http_main.h - apache server handling ➢ http_log.h - logging facilities ➢ For Apache 2.0 and 2.2 ➢ some apache common functions are moved in apr_strings.h ➢ in order to use the request and protocol functionality you would need also http_connection.h ➢ if you need server implementation functions you need ap_mpm.h ➢ These are not all includes that you may need in your modules
  • 11. Module names #ifdef APACHE2 module AP_MODULE_DECLARE_DATA example_module; #else module MODULE_VAR_EXPORT example_module; #endif
  • 12. Module definition ➢ Apache 1.3 ➢ Apache 2.x
  • 13. Apache 1.3 module MODULE_VAR_EXPORT example_module = { STANDARD_MODULE_STUFF, NULL, /* module initializer */ NULL, /* per-directory config creator */ NULL, /* dir config merger */ NULL, /* server config creator */ NULL, /* server config merger */ NULL, /* command table */ NULL, /* [9] list of handlers */ NULL, /* [2] filename-to-URI translation */ NULL, /* [5] check/validate user_id */
  • 14. Apache 1.3 NULL, /* [6] check user_id is valid *here* */ NULL, /* [4] check access by host address */ NULL, /* [7] MIME type checker/setter */ NULL, /* [8] fixups */ NULL, /* [10] logger */ NULL, /* [3] header parser */ NULL, /* process initializer */ NULL, /* process exit/cleanup */ NULL /* [1] post read_request handling */ };
  • 15. Apache 2.x module AP_MODULE_DECLARE_DATA example_module = { STANDARD20_MODULE_STUFF, NULL, /* per-directory config creator */ NULL, /* dir config merger */ NULL, /* server config creator */ NULL, /* server config merger */ NULL, /* command table */ NULL, /* set up other request processing hooks */ }; static void register_hooks(apr_pool_t *p) { static const char * const aszPost[] = { "mod_setenvif.c", NULL }; /* 19 different processing hooks available */ }
  • 16. Module initialization ➢ Apache 1.3 ➢ startup and live ➢ the function is called two times ➢ Apache 2.0/2.2 module structure ➢ pre-config ➢ post-config
  • 17. Creating new configuration directives ➢ Define them in the module configuration structure ➢ Define new module commands(options) ➢ Create functions to actually set the options, when found in the config
  • 18. Module configuration structure typedef struct { double dummy_double; int dummy_int; char *dummy_char; array_header *dummy_array; } example_conf;
  • 19. Array handling struct ip_range *net; char *proxies[] = IP_RANGES; pool *p; conf->nets = ap_make_array(p, IP_RANGES_COUNT, sizeof(struct ip_range)); for (i = 0; i < IP_RANGES_COUNT; i++) { net = (struct ip_range *) ap_push_array(conf->nets); parse_ip( p, proxies[ i ], net ); }
  • 20. Module commands(options) ➢ Apache 1.3 static const command_rec example_cmds[] = { { "Example", cmd_example, NULL, /* argument to include in call */ OR_OPTIONS, NO_ARGS, "Example directive - no arguments" }, {NULL} };
  • 21. Module commands(options) ➢ Apache 2.x static const command_rec x_cmds[] = { AP_INIT_NO_ARGS( "Example", cmd_example, NULL, /* argument to include in call */ OR_OPTIONS, "Example directive - no arguments" ), {NULL} };
  • 22. Possible arguments ➢ FLAG => One of 'On' or 'Off' ➢ NO_ARGS => No args at all, e.g. </Directory> ➢ RAW_ARGS => cmd_func parses command line itself ➢ TAKE1 => one argument only ➢ TAKE2 => two arguments only ➢ ITERATE => one argument, occuring multiple times ➢ ITERATE2 => two arguments, 2nd occurs multiple times ➢ TAKE12 => one or two arguments ➢ TAKE3 => three arguments only ➢ TAKE23 => two or three arguments ➢ TAKE123 => one, two or three arguments ➢ TAKE13 => one or three arguments
  • 23. Allowed locations for configuration directives ➢ RSRC_CONF => *.conf outside <Directory> or <Location> ➢ ACCESS_CONF => *.conf inside <Directory> or <Location> ➢ OR_AUTHCFG) => *.conf inside <Directory> or <Location> and .htaccess when AllowOverride AuthConfig ➢ OR_LIMIT) => *.conf inside <Directory> or <Location> and .htaccess when AllowOverride Limit ➢ OR_OPTIONS) => *.conf anywhere and .htaccess when AllowOverride Options ➢ OR_FILEINFO) => *.conf anywhere and .htaccess when AllowOverride FileInfo ➢ OR_INDEXES) => *.conf anywhere and .htaccess when AllowOverride Indexes
  • 24. Module command handlers static const char *set_examplecmd(cmd_parms *cmd, void *vconf, char *arg) { example_conf *conf = (example_conf *) vconf; if (cmd->path == NULL) { conf = (example_conf *) ap_get_module_config(cmd->server->module_config, &example_module); #ifdef DEBUG_OPTIONS fprintf(stderr, "mod_example: (%s:%d)Example (server)n", cmd->config_file->name, cmd->config_file->line_number); } else { fprintf(stderr, "mod_example: (%s:%d)RelaxPerms (dir)n", cmd->config_file->name, cmd->config_file->line_number); #endif } conf->dummy_char = ap_pstrdup(cmd->pool, arg); return NULL; }
  • 25. Handling configuration directives ➢ Global vs. Vhost configuration ➢ Per directory/files/location ➢ Merge of the global and per-vhost configuration ➢ Initialization of the configuration
  • 26. Logging ➢ ap_log_error(APLOG_MARK, APLOG_INFO, r->server, "Some string"); ➢ ap_log_rerror(APLOG_MARK, APLOG_INFO, r, "Some string"); ➢ Apache 2.x ➢ Added ap_log_cerror() for conn_rec handling ➢ Added ap_log_perror() for everything that is not server, record or connection related ➢ Added status code between the server and level
  • 27. Writing portable modules ➢ Porting tricks #ifndef APACHE_RELEASE #define APACHE2 #endif ➢ Apache common functions ➢ ap_palloc(1.3) -> apr_palloc(2.x)
  • 29. Thank you ??? Questions ??? Thank you