Changeset 53 for trunk/lib


Ignore:
Timestamp:
09/04/05 17:04:58 (19 years ago)
Author:
tim
Message:

Moved security descriptor parsing functions into regfio.c

Improved malloc() mode of failure.

Eliminated some warnings in regfio.c

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfio.c

    r41 r53  
    2929
    3030
    31 /*******************************************************************
    32  *
    33  * TODO : Right now this code basically ignores classnames.
    34  *
    35  ******************************************************************/
    36 
    3731/* Registry types mapping */
    3832const VAL_STR reg_type_names[] =
     
    7973
    8074
     75/* Security descriptor parsing functions  */
     76
     77const char* regfio_ace_type2str(uint8 type)
     78{
     79  static const char* map[7]
     80    = {"ALLOW", "DENY", "AUDIT", "ALARM",
     81       "ALLOW CPD", "OBJ ALLOW", "OBJ DENY"};
     82  if(type < 7)
     83    return map[type];
     84  else
     85    /* XXX: would be nice to return the unknown integer value. 
     86     *      However, as it is a const string, it can't be free()ed later on,
     87     *      so that would need to change.
     88     */
     89    return "UNKNOWN";
     90}
     91
     92
     93/* XXX: this could probably be more efficient */
     94char* regfio_ace_flags2str(uint8 flags)
     95{
     96  char* flg_output = malloc(21*sizeof(char));
     97  int some = 0;
     98
     99  if(flg_output == NULL)
     100    return NULL;
     101
     102  flg_output[0] = '\0';
     103  if (!flags)
     104    return flg_output;
     105
     106  if (flags & 0x01) {
     107    if (some) strcat(flg_output, " ");
     108    some = 1;
     109    strcat(flg_output, "OI");
     110  }
     111  if (flags & 0x02) {
     112    if (some) strcat(flg_output, " ");
     113    some = 1;
     114    strcat(flg_output, "CI");
     115  }
     116  if (flags & 0x04) {
     117    if (some) strcat(flg_output, " ");
     118    some = 1;
     119    strcat(flg_output, "NP");
     120  }
     121  if (flags & 0x08) {
     122    if (some) strcat(flg_output, " ");
     123    some = 1;
     124    strcat(flg_output, "IO");
     125  }
     126  if (flags & 0x10) {
     127    if (some) strcat(flg_output, " ");
     128    some = 1;
     129    strcat(flg_output, "IA");
     130  }
     131  if (flags == 0xF) {
     132    if (some) strcat(flg_output, " ");
     133    some = 1;
     134    strcat(flg_output, "VI");
     135  }
     136
     137  return flg_output;
     138}
     139
     140
     141char* regfio_ace_perms2str(uint32 perms)
     142{
     143  char* ret_val = malloc(9*sizeof(char));
     144  if(ret_val == NULL)
     145    return NULL;
     146
     147  /* XXX: this should probably be parsed better */
     148  sprintf(ret_val, "%.8X", perms);
     149
     150  return ret_val;
     151}
     152
     153
     154char* regfio_sid2str(DOM_SID* sid)
     155{
     156  uint32 i, size = MAXSUBAUTHS*11 + 24;
     157  uint32 left = size;
     158  uint8 comps = sid->num_auths;
     159  char* ret_val = malloc(size);
     160 
     161  if(ret_val == NULL)
     162    return NULL;
     163
     164  if(comps > MAXSUBAUTHS)
     165    comps = MAXSUBAUTHS;
     166
     167  left -= sprintf(ret_val, "S-%u-%u", sid->sid_rev_num, sid->id_auth[5]);
     168
     169  for (i = 0; i < comps; i++)
     170    left -= snprintf(ret_val+(size-left), left, "-%u", sid->sub_auths[i]);
     171
     172  return ret_val;
     173}
     174
     175
     176char* regfio_get_acl(SEC_ACL* acl)
     177{
     178  uint32 i, extra, size = 0;
     179  const char* type_str;
     180  char* flags_str;
     181  char* perms_str;
     182  char* sid_str;
     183  char* ret_val = NULL;
     184  char* ace_delim = "";
     185  char field_delim = ':';
     186
     187  for (i = 0; i < acl->num_aces; i++)
     188  {
     189    sid_str = regfio_sid2str(&acl->ace[i].trustee);
     190    type_str = regfio_ace_type2str(acl->ace[i].type);
     191    perms_str = regfio_ace_perms2str(acl->ace[i].info.mask);
     192    flags_str = regfio_ace_flags2str(acl->ace[i].flags);
     193   
     194    if(flags_str == NULL || perms_str == NULL
     195       || type_str == NULL || sid_str == NULL)
     196      return NULL;
     197
     198    /* XXX: this is slow */
     199    extra = strlen(sid_str) + strlen(type_str)
     200          + strlen(perms_str) + strlen(flags_str)+5;
     201    ret_val = realloc(ret_val, size+extra);
     202    if(ret_val == NULL)
     203      return NULL;
     204    size += snprintf(ret_val+size, extra, "%s%s%c%s%c%s%c%s",
     205                     ace_delim,sid_str,
     206                     field_delim,type_str,
     207                     field_delim,perms_str,
     208                     field_delim,flags_str);
     209    ace_delim = "|";
     210    free(sid_str);
     211    free(perms_str);
     212    free(flags_str);
     213  }
     214
     215  return ret_val;
     216}
     217
     218
     219char* regfio_get_sacl(SEC_DESC *sec_desc)
     220{
     221  if (sec_desc->sacl)
     222    return regfio_get_acl(sec_desc->sacl);
     223  else
     224    return NULL;
     225}
     226
     227
     228char* regfio_get_dacl(SEC_DESC *sec_desc)
     229{
     230  if (sec_desc->dacl)
     231    return regfio_get_acl(sec_desc->dacl);
     232  else
     233    return NULL;
     234}
     235
     236
     237char* regfio_get_owner(SEC_DESC *sec_desc)
     238{
     239  return regfio_sid2str(sec_desc->owner_sid);
     240}
     241
     242
     243char* regfio_get_group(SEC_DESC *sec_desc)
     244{
     245  return regfio_sid2str(sec_desc->grp_sid);
     246}
     247
     248
     249
    81250/*******************************************************************
    82251 *******************************************************************/
     
    117286    /* make sure this is an hbin header */
    118287
    119     if ( strncmp( hdr, "hbin", HBIN_HDR_SIZE ) != 0 ) {
     288    if ( strncmp( (char*)hdr, "hbin", HBIN_HDR_SIZE ) != 0 ) {
    120289      /*DEBUG(0,("read_block: invalid block header!\n"));*/
    121290      return -1;
     
    161330/*******************************************************************
    162331 *******************************************************************/
    163 static bool prs_regf_block( const char *desc, prs_struct *ps, int depth, REGF_FILE *file )
     332static bool prs_regf_block(const char *desc, prs_struct *ps,
     333                           int depth, REGF_FILE *file)
    164334{
    165335  depth++;
    166336       
    167   if ( !prs_uint8s( true, "header", ps, depth, file->header, sizeof( file->header )) )
     337  if(!prs_uint8s(true, "header", ps, depth, file->header, sizeof(file->header)))
    168338    return false;
    169339       
     
    220390/*******************************************************************
    221391 *******************************************************************/
    222 static bool prs_hbin_block( const char *desc, prs_struct *ps, int depth, REGF_HBIN *hbin )
     392static bool prs_hbin_block(const char *desc, prs_struct *ps,
     393                           int depth, REGF_HBIN *hbin)
    223394{
    224395  uint32 block_size2;
     
    226397  depth++;
    227398       
    228   if ( !prs_uint8s( true, "header", ps, depth, hbin->header, sizeof( hbin->header )) )
     399  if(!prs_uint8s(true, "header", ps, depth, hbin->header, sizeof(hbin->header)))
    229400    return false;
    230401
     
    336507        return false;
    337508
    338     if ( !prs_uint8s( true, "name", ps, depth, nk->keyname, name_length) )
    339       return false;
    340 
    341     if ( ps->io )
     509    if(!prs_uint8s(true, "name", ps, depth, (uint8*)nk->keyname, name_length))
     510      return false;
     511
     512    if(ps->io)
    342513      nk->keyname[name_length] = '\0';
    343514  }
     
    583754/*******************************************************************
    584755 *******************************************************************/
    585 static bool hbin_prs_lf_records( const char *desc, REGF_HBIN *hbin, int depth, REGF_NK_REC *nk )
     756static bool hbin_prs_lf_records(const char *desc, REGF_HBIN *hbin,
     757                                int depth, REGF_NK_REC *nk)
    586758{
    587759  int i;
     
    609781    return false;
    610782
    611   if ( !prs_uint8s( true, "header", &hbin->ps, depth, lf->header, sizeof( lf->header )) )
     783  if(!prs_uint8s(true, "header", &hbin->ps, depth,
     784                 lf->header, sizeof(lf->header)))
    612785    return false;
    613786               
     
    662835    return false;
    663836
    664   if ( !prs_uint8s( true, "header", ps, depth, sk->header, sizeof( sk->header )) )
     837  if (!prs_uint8s(true, "header", ps, depth, sk->header, sizeof(sk->header)))
    665838    return false;
    666839  if ( !prs_uint16( "tag", ps, depth, &tag))
     
    743916        return false;
    744917    }
    745     if ( !prs_uint8s( true, "name", ps, depth, vk->valuename, name_length ) )
     918    if ( !prs_uint8s(true, "name", ps, depth,
     919                     (uint8*)vk->valuename, name_length) )
    746920      return false;
    747921  }
     
    10171191static bool next_record( REGF_HBIN *hbin, const char *hdr, bool *eob )
    10181192{
    1019   char header[REC_HDR_SIZE] = "";
     1193  uint8 header[REC_HDR_SIZE] = "";
    10201194  uint32 record_size;
    10211195  uint32 curr_off, block_size;
  • trunk/lib/smb_deps.c

    r42 r53  
    427427 Stream an array of uint8s. Length is number of uint8s.
    428428 ********************************************************************/
    429 bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, uint8 *data8s, int len)
     429bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth,
     430                uint8* data8s, int len)
    430431{
    431432        int i;
Note: See TracChangeset for help on using the changeset viewer.