mirror of
https://github.com/samba-team/samba.git
synced 2025-12-17 04:23:50 +03:00
Remove more pstring. Unify talloc_sub functions to make
them a better match for replacing string_sub. Remove more unused code. Jeremy.
This commit is contained in:
@@ -1274,11 +1274,15 @@ char *realloc_string_sub(char *string,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal guts of talloc_string_sub and talloc_all_string_sub.
|
* Internal guts of talloc_string_sub and talloc_all_string_sub.
|
||||||
* 'filter' differentiates between them.
|
* talloc version of string_sub2.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *talloc_string_sub_internal(TALLOC_CTX *mem_ctx, const char *src,
|
char *talloc_string_sub2(TALLOC_CTX *mem_ctx, const char *src,
|
||||||
const char *pattern, const char *insert, bool filter)
|
const char *pattern,
|
||||||
|
const char *insert,
|
||||||
|
bool remove_unsafe_characters,
|
||||||
|
bool replace_once,
|
||||||
|
bool allow_trailing_dollar)
|
||||||
{
|
{
|
||||||
char *p, *in;
|
char *p, *in;
|
||||||
char *s;
|
char *s;
|
||||||
@@ -1291,7 +1295,7 @@ static char *talloc_string_sub_internal(TALLOC_CTX *mem_ctx, const char *src,
|
|||||||
|
|
||||||
string = talloc_strdup(mem_ctx, src);
|
string = talloc_strdup(mem_ctx, src);
|
||||||
if (string == NULL) {
|
if (string == NULL) {
|
||||||
DEBUG(0, ("talloc_string_sub_internal: "
|
DEBUG(0, ("talloc_string_sub2: "
|
||||||
"talloc_strdup failed\n"));
|
"talloc_strdup failed\n"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1300,7 +1304,7 @@ static char *talloc_string_sub_internal(TALLOC_CTX *mem_ctx, const char *src,
|
|||||||
|
|
||||||
in = SMB_STRDUP(insert);
|
in = SMB_STRDUP(insert);
|
||||||
if (!in) {
|
if (!in) {
|
||||||
DEBUG(0, ("talloc_string_sub_internal: ENOMEM\n"));
|
DEBUG(0, ("talloc_string_sub2: ENOMEM\n"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ls = (ssize_t)strlen(s);
|
ls = (ssize_t)strlen(s);
|
||||||
@@ -1308,22 +1312,28 @@ static char *talloc_string_sub_internal(TALLOC_CTX *mem_ctx, const char *src,
|
|||||||
li = (ssize_t)strlen(insert);
|
li = (ssize_t)strlen(insert);
|
||||||
ld = li - lp;
|
ld = li - lp;
|
||||||
|
|
||||||
if (filter) {
|
for (i=0;i<li;i++) {
|
||||||
for (i=0;i<li;i++) {
|
switch (in[i]) {
|
||||||
switch (in[i]) {
|
case '`':
|
||||||
case '`':
|
case '"':
|
||||||
case '"':
|
case '\'':
|
||||||
case '\'':
|
case ';':
|
||||||
case ';':
|
case '$':
|
||||||
case '$':
|
/* allow a trailing $
|
||||||
case '%':
|
* (as in machine accounts) */
|
||||||
case '\r':
|
if (allow_trailing_dollar && (i == li - 1 )) {
|
||||||
case '\n':
|
|
||||||
in[i] = '_';
|
|
||||||
default:
|
|
||||||
/* ok */
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case '%':
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
if (remove_unsafe_characters) {
|
||||||
|
in[i] = '_';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
/* ok */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1346,6 +1356,10 @@ static char *talloc_string_sub_internal(TALLOC_CTX *mem_ctx, const char *src,
|
|||||||
memcpy(p, in, li);
|
memcpy(p, in, li);
|
||||||
s = p + li;
|
s = p + li;
|
||||||
ls += ld;
|
ls += ld;
|
||||||
|
|
||||||
|
if (replace_once) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SAFE_FREE(in);
|
SAFE_FREE(in);
|
||||||
return string;
|
return string;
|
||||||
@@ -1353,10 +1367,13 @@ static char *talloc_string_sub_internal(TALLOC_CTX *mem_ctx, const char *src,
|
|||||||
|
|
||||||
/* Same as string_sub, but returns a talloc'ed string */
|
/* Same as string_sub, but returns a talloc'ed string */
|
||||||
|
|
||||||
char *talloc_string_sub(TALLOC_CTX *mem_ctx, const char *src,
|
char *talloc_string_sub(TALLOC_CTX *mem_ctx,
|
||||||
const char *pattern, const char *insert)
|
const char *src,
|
||||||
|
const char *pattern,
|
||||||
|
const char *insert)
|
||||||
{
|
{
|
||||||
return talloc_string_sub_internal(mem_ctx, src, pattern, insert, true);
|
return talloc_string_sub2(mem_ctx, src, pattern, insert,
|
||||||
|
true, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1406,73 +1423,8 @@ char *talloc_all_string_sub(TALLOC_CTX *ctx,
|
|||||||
const char *pattern,
|
const char *pattern,
|
||||||
const char *insert)
|
const char *insert)
|
||||||
{
|
{
|
||||||
return talloc_string_sub_internal(ctx, src, pattern, insert, false);
|
return talloc_string_sub2(ctx, src, pattern, insert,
|
||||||
}
|
false, false, false);
|
||||||
|
|
||||||
/**
|
|
||||||
Similar to all_string_sub but for unicode strings.
|
|
||||||
Return a new allocated unicode string.
|
|
||||||
similar to string_sub() but allows for any character to be substituted.
|
|
||||||
Use with caution!
|
|
||||||
**/
|
|
||||||
|
|
||||||
static smb_ucs2_t *all_string_sub_w(const smb_ucs2_t *s,
|
|
||||||
const smb_ucs2_t *pattern,
|
|
||||||
const smb_ucs2_t *insert)
|
|
||||||
{
|
|
||||||
smb_ucs2_t *r, *rp;
|
|
||||||
const smb_ucs2_t *sp;
|
|
||||||
size_t lr, lp, li, lt;
|
|
||||||
|
|
||||||
if (!insert || !pattern || !*pattern || !s)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
lt = (size_t)strlen_w(s);
|
|
||||||
lp = (size_t)strlen_w(pattern);
|
|
||||||
li = (size_t)strlen_w(insert);
|
|
||||||
|
|
||||||
if (li > lp) {
|
|
||||||
const smb_ucs2_t *st = s;
|
|
||||||
int ld = li - lp;
|
|
||||||
while ((sp = strstr_w(st, pattern))) {
|
|
||||||
st = sp + lp;
|
|
||||||
lt += ld;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r = rp = SMB_MALLOC_ARRAY(smb_ucs2_t, lt + 1);
|
|
||||||
if (!r) {
|
|
||||||
DEBUG(0, ("all_string_sub_w: out of memory!\n"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((sp = strstr_w(s, pattern))) {
|
|
||||||
memcpy(rp, s, (sp - s));
|
|
||||||
rp += ((sp - s) / sizeof(smb_ucs2_t));
|
|
||||||
memcpy(rp, insert, (li * sizeof(smb_ucs2_t)));
|
|
||||||
s = sp + lp;
|
|
||||||
rp += li;
|
|
||||||
}
|
|
||||||
lr = ((rp - r) / sizeof(smb_ucs2_t));
|
|
||||||
if (lr < lt) {
|
|
||||||
memcpy(rp, s, ((lt - lr) * sizeof(smb_ucs2_t)));
|
|
||||||
rp += (lt - lr);
|
|
||||||
}
|
|
||||||
*rp = 0;
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
smb_ucs2_t *all_string_sub_wa(smb_ucs2_t *s, const char *pattern,
|
|
||||||
const char *insert)
|
|
||||||
{
|
|
||||||
wpstring p, i;
|
|
||||||
|
|
||||||
if (!insert || !pattern || !s)
|
|
||||||
return NULL;
|
|
||||||
push_ucs2(NULL, p, pattern, sizeof(wpstring) - 1, STR_TERMINATE);
|
|
||||||
push_ucs2(NULL, i, insert, sizeof(wpstring) - 1, STR_TERMINATE);
|
|
||||||
return all_string_sub_w(s, p, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
@@ -125,9 +125,13 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first)
|
|||||||
|
|
||||||
char *tok[MAXTOK];
|
char *tok[MAXTOK];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
pstring line2;
|
TALLOC_CTX *ctx = talloc_tos();
|
||||||
|
char *line2 = NULL;
|
||||||
|
|
||||||
pstrcpy(line2,line);
|
line2 = talloc_strdup(ctx, line);
|
||||||
|
if (!line2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef OSF1
|
#ifdef OSF1
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -180,13 +180,11 @@ static int get_queue_status(const char* sharename, print_status_struct *);
|
|||||||
bool print_backend_init(struct messaging_context *msg_ctx)
|
bool print_backend_init(struct messaging_context *msg_ctx)
|
||||||
{
|
{
|
||||||
const char *sversion = "INFO/version";
|
const char *sversion = "INFO/version";
|
||||||
pstring printing_path;
|
|
||||||
int services = lp_numservices();
|
int services = lp_numservices();
|
||||||
int snum;
|
int snum;
|
||||||
|
|
||||||
unlink(lock_path("printing.tdb"));
|
unlink(lock_path("printing.tdb"));
|
||||||
pstrcpy(printing_path,lock_path("printing"));
|
mkdir(lock_path("printing"),0755);
|
||||||
mkdir(printing_path,0755);
|
|
||||||
|
|
||||||
/* handle a Samba upgrade */
|
/* handle a Samba upgrade */
|
||||||
|
|
||||||
@@ -1443,43 +1441,66 @@ static void print_queue_update(int snum, bool force)
|
|||||||
{
|
{
|
||||||
fstring key;
|
fstring key;
|
||||||
fstring sharename;
|
fstring sharename;
|
||||||
pstring lpqcommand, lprmcommand;
|
char *lpqcommand = NULL;
|
||||||
|
char *lprmcommand = NULL;
|
||||||
uint8 *buffer = NULL;
|
uint8 *buffer = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
size_t newlen;
|
size_t newlen;
|
||||||
struct tdb_print_db *pdb;
|
struct tdb_print_db *pdb;
|
||||||
int type;
|
int type;
|
||||||
struct printif *current_printif;
|
struct printif *current_printif;
|
||||||
|
TALLOC_CTX *ctx = talloc_tos();
|
||||||
|
|
||||||
fstrcpy( sharename, lp_const_servicename(snum));
|
fstrcpy( sharename, lp_const_servicename(snum));
|
||||||
|
|
||||||
/* don't strip out characters like '$' from the printername */
|
/* don't strip out characters like '$' from the printername */
|
||||||
|
|
||||||
pstrcpy( lpqcommand, lp_lpqcommand(snum));
|
lpqcommand = talloc_string_sub2(ctx,
|
||||||
string_sub2( lpqcommand, "%p", PRINTERNAME(snum), sizeof(lpqcommand),
|
lp_lpqcommand(snum),
|
||||||
False, False, False );
|
"%p",
|
||||||
standard_sub_advanced(lp_servicename(snum),
|
PRINTERNAME(snum),
|
||||||
current_user_info.unix_name, "",
|
false, false, false);
|
||||||
current_user.ut.gid,
|
if (!lpqcommand) {
|
||||||
get_current_username(),
|
return;
|
||||||
current_user_info.domain,
|
}
|
||||||
lpqcommand, sizeof(lpqcommand) );
|
lpqcommand = talloc_sub_advanced(ctx,
|
||||||
|
lp_servicename(snum),
|
||||||
|
current_user_info.unix_name,
|
||||||
|
"",
|
||||||
|
current_user.ut.gid,
|
||||||
|
get_current_username(),
|
||||||
|
current_user_info.domain,
|
||||||
|
lpqcommand);
|
||||||
|
if (!lpqcommand) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pstrcpy( lprmcommand, lp_lprmcommand(snum));
|
pstrcpy( lprmcommand, lp_lprmcommand(snum));
|
||||||
string_sub2( lprmcommand, "%p", PRINTERNAME(snum), sizeof(lprmcommand),
|
lprmcommand = talloc_string_sub2(ctx,
|
||||||
False, False, False );
|
lp_lprmcommand(snum),
|
||||||
standard_sub_advanced(lp_servicename(snum),
|
"%p",
|
||||||
current_user_info.unix_name, "",
|
PRINTERNAME(snum),
|
||||||
current_user.ut.gid,
|
false, false, false);
|
||||||
get_current_username(),
|
if (!lprmcommand) {
|
||||||
current_user_info.domain,
|
return;
|
||||||
lprmcommand, sizeof(lprmcommand) );
|
}
|
||||||
|
lprmcommand = talloc_sub_advanced(ctx,
|
||||||
/*
|
lp_servicename(snum),
|
||||||
* Make sure that the background queue process exists.
|
current_user_info.unix_name,
|
||||||
* Otherwise just do the update ourselves
|
"",
|
||||||
|
current_user.ut.gid,
|
||||||
|
get_current_username(),
|
||||||
|
current_user_info.domain,
|
||||||
|
lprmcommand);
|
||||||
|
if (!lprmcommand) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make sure that the background queue process exists.
|
||||||
|
* Otherwise just do the update ourselves
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( force || background_lpq_updater_pid == -1 ) {
|
if ( force || background_lpq_updater_pid == -1 ) {
|
||||||
DEBUG(4,("print_queue_update: updating queue [%s] myself\n", sharename));
|
DEBUG(4,("print_queue_update: updating queue [%s] myself\n", sharename));
|
||||||
current_printif = get_printer_fns( snum );
|
current_printif = get_printer_fns( snum );
|
||||||
@@ -1489,13 +1510,13 @@ static void print_queue_update(int snum, bool force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
type = lp_printing(snum);
|
type = lp_printing(snum);
|
||||||
|
|
||||||
/* get the length */
|
/* get the length */
|
||||||
|
|
||||||
len = tdb_pack( NULL, 0, "fdPP",
|
len = tdb_pack( NULL, 0, "fdPP",
|
||||||
sharename,
|
sharename,
|
||||||
type,
|
type,
|
||||||
lpqcommand,
|
lpqcommand,
|
||||||
lprmcommand );
|
lprmcommand );
|
||||||
|
|
||||||
buffer = SMB_XMALLOC_ARRAY( uint8, len );
|
buffer = SMB_XMALLOC_ARRAY( uint8, len );
|
||||||
|
|||||||
Reference in New Issue
Block a user