2005-01-05 19:20:35 +03:00
/*
AIX - specific printcap loading
Copyright ( C ) Jean - Pierre . Boulard @ univ - rennes1 . fr 1996
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-05 19:20:35 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-05 19:20:35 +03:00
*/
/*
* This module implements AIX - specific printcap loading . Most of the code
* here was originally provided by Jean - Pierre . Boulard @ univ - rennes1 . fr in
* the Samba 1.9 .14 release , and was formerly contained in pcap . c . It has
* been moved here and condensed as part of a larger effort to clean up and
* simplify the printcap code . - - Rob Foehl , 2004 / 12 / 06
*/
# include "includes.h"
2011-04-20 19:54:24 +04:00
# include "system/filesys.h"
2010-05-14 16:39:40 +04:00
# include "printing/pcap.h"
2005-01-05 19:20:35 +03:00
# ifdef AIX
2014-07-22 22:17:38 +04:00
bool aix_cache_reload ( struct pcap_cache * * _pcache )
2005-01-05 19:20:35 +03:00
{
int iEtat ;
2016-11-26 17:33:06 +03:00
FILE * pfile ;
2005-01-05 19:20:35 +03:00
char * line = NULL , * p ;
2007-12-11 00:43:12 +03:00
char * name = NULL ;
2014-07-22 22:17:38 +04:00
struct pcap_cache * pcache = NULL ;
2007-11-22 00:56:36 +03:00
TALLOC_CTX * ctx = talloc_init ( " aix_cache_reload " ) ;
if ( ! ctx ) {
return false ;
}
2005-01-05 19:20:35 +03:00
DEBUG ( 5 , ( " reloading aix printcap cache \n " ) ) ;
2016-11-26 17:33:06 +03:00
if ( ( pfile = fopen ( lp_printcapname ( ) , " r " ) ) = = NULL ) {
2005-01-05 19:20:35 +03:00
DEBUG ( 0 , ( " Unable to open qconfig file %s for read! \n " , lp_printcapname ( ) ) ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return false ;
2005-01-05 19:20:35 +03:00
}
iEtat = 0 ;
/* scan qconfig file for searching <printername>: */
2016-11-26 17:33:06 +03:00
while ( line = fgets_slash ( ctx , NULL , 1024 , pfile ) ) {
2014-07-22 22:17:38 +04:00
bool ok ;
2016-11-26 17:33:06 +03:00
if ( * line = = ' * ' | | * line = = 0 ) {
TALLOC_FREE ( line ) ;
2005-01-05 19:20:35 +03:00
continue ;
2016-11-26 17:33:06 +03:00
}
2005-01-05 19:20:35 +03:00
switch ( iEtat ) {
case 0 : /* locate an entry */
2016-11-26 17:33:06 +03:00
if ( * line = = ' \t ' | | * line = = ' ' ) {
TALLOC_FREE ( line ) ;
2005-01-05 19:20:35 +03:00
continue ;
2016-11-26 17:33:06 +03:00
}
2005-01-05 19:20:35 +03:00
if ( ( p = strchr_m ( line , ' : ' ) ) ) {
2008-01-23 13:04:10 +03:00
char * saveptr ;
2005-01-05 19:20:35 +03:00
* p = ' \0 ' ;
2008-01-23 13:04:10 +03:00
p = strtok_r ( line , " : " , & saveptr ) ;
2005-01-05 19:20:35 +03:00
if ( strcmp ( p , " bsh " ) ! = 0 ) {
2007-11-22 00:56:36 +03:00
name = talloc_strdup ( ctx , p ) ;
if ( ! name ) {
2014-07-22 22:17:38 +04:00
pcap_cache_destroy_specific ( & pcache ) ;
2016-11-26 17:33:06 +03:00
TALLOC_FREE ( line ) ;
fclose ( pfile ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return false ;
}
2005-01-05 19:20:35 +03:00
iEtat = 1 ;
continue ;
}
}
break ;
case 1 : /* scanning device stanza */
if ( * line = = ' * ' | | * line = = 0 )
continue ;
if ( * line ! = ' \t ' & & * line ! = ' ' ) {
/* name is found without stanza device */
/* probably a good printer ??? */
iEtat = 0 ;
2014-07-22 22:17:38 +04:00
ok = pcap_cache_add_specific ( & pcache ,
name , NULL , NULL ) ;
if ( ! ok ) {
pcap_cache_destroy_specific ( & pcache ) ;
2016-11-26 17:33:06 +03:00
TALLOC_FREE ( line ) ;
fclose ( pfile ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return false ;
2005-01-05 19:20:35 +03:00
}
continue ;
}
2007-11-22 00:56:36 +03:00
2005-01-05 19:20:35 +03:00
if ( strstr_m ( line , " backend " ) ) {
/* it's a device, not a virtual printer */
iEtat = 0 ;
} else if ( strstr_m ( line , " device " ) ) {
/* it's a good virtual printer */
iEtat = 0 ;
2014-07-22 22:17:38 +04:00
ok = pcap_cache_add_specific ( & pcache ,
name , NULL , NULL ) ;
if ( ! ok ) {
pcap_cache_destroy_specific ( & pcache ) ;
2008-10-19 15:06:14 +04:00
SAFE_FREE ( line ) ;
2016-11-26 17:33:06 +03:00
fclose ( pfile ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return false ;
2005-01-05 19:20:35 +03:00
}
continue ;
}
break ;
}
}
2014-07-22 22:17:38 +04:00
* _pcache = pcache ;
2016-11-26 17:33:06 +03:00
fclose ( pfile ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return true ;
2005-01-05 19:20:35 +03:00
}
# else
/* this keeps fussy compilers happy */
void print_aix_dummy ( void ) ;
void print_aix_dummy ( void ) { }
# endif /* AIX */