Changeset 59 for trunk


Ignore:
Timestamp:
10/02/05 21:26:12 (19 years ago)
Author:
tim
Message:

Updated version

Code format cleanup, some comments added.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfio.c

    r53 r59  
    129129    strcat(flg_output, "IA");
    130130  }
     131  /* XXX: Is this check right?  0xF == 1|2|4|8, which makes it redundant... */
    131132  if (flags == 0xF) {
    132133    if (some) strcat(flg_output, " ");
  • trunk/lib/smb_deps.c

    r53 r59  
    5151void unix_to_nt_time(NTTIME *nt, time_t t)
    5252{
    53         double d;
    54 
    55         if (t==0) {
    56                 nt->low = 0;
    57                 nt->high = 0;
    58                 return;
    59         }
    60         if (t == TIME_T_MAX) {
    61                 nt->low = 0xffffffff;
    62                 nt->high = 0x7fffffff;
    63                 return;
    64         }               
    65         if (t == -1) {
    66                 nt->low = 0xffffffff;
    67                 nt->high = 0xffffffff;
    68                 return;
    69         }               
    70 
    71         /* this converts GMT to kludge-GMT */
    72         /*XXX t -= TimeDiff(t) - get_serverzone(); */
    73 
    74         d = (double)(t);
    75         d += TIME_FIXUP_CONSTANT;
    76         d *= 1.0e7;
    77 
    78         nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
    79         nt->low  = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
     53  double d;
     54 
     55  if (t==0)
     56  {
     57    nt->low = 0;
     58    nt->high = 0;
     59    return;
     60  }
     61 
     62  if (t == TIME_T_MAX)
     63  {
     64    nt->low = 0xffffffff;
     65    nt->high = 0x7fffffff;
     66    return;
     67  }             
     68 
     69  if (t == -1)
     70  {
     71    nt->low = 0xffffffff;
     72    nt->high = 0xffffffff;
     73    return;
     74  }             
     75 
     76  /* this converts GMT to kludge-GMT */
     77  /* XXX: This was removed due to difficult dependency requirements. 
     78   *      So far, times appear to be correct without this adjustment, but
     79   *      that may be proven wrong with adequate testing.
     80   */
     81  /* t -= TimeDiff(t) - get_serverzone(); */
     82 
     83  d = (double)(t);
     84  d += TIME_FIXUP_CONSTANT;
     85  d *= 1.0e7;
     86 
     87  nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
     88  nt->low  = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
    8089}
    8190
     
    94103time_t nt_time_to_unix(NTTIME *nt)
    95104{
    96         double d;
    97         time_t ret;
    98         /* The next two lines are a fix needed for the
    99                 broken SCO compiler. JRA. */
    100         time_t l_time_min = TIME_T_MIN;
    101         time_t l_time_max = TIME_T_MAX;
    102 
    103         if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff))
    104                 return(0);
    105 
    106         d = ((double)nt->high)*4.0*(double)(1<<30);
    107         d += (nt->low&0xFFF00000);
    108         d *= 1.0e-7;
    109  
    110         /* now adjust by 369 years to make the secs since 1970 */
    111         d -= TIME_FIXUP_CONSTANT;
    112 
    113         if (d <= l_time_min)
    114                 return (l_time_min);
    115 
    116         if (d >= l_time_max)
    117                 return (l_time_max);
    118 
    119         ret = (time_t)(d+0.5);
    120 
    121         /* this takes us from kludge-GMT to real GMT */
    122         /*XXX
    123         ret -= get_serverzone();
    124         ret += LocTimeDiff(ret);
    125         */
    126         return(ret);
    127 }
    128 
     105  double d;
     106  time_t ret;
     107  /* The next two lines are a fix needed for the
     108     broken SCO compiler. JRA. */
     109  time_t l_time_min = TIME_T_MIN;
     110  time_t l_time_max = TIME_T_MAX;
     111 
     112  if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff))
     113    return(0);
     114 
     115  d = ((double)nt->high)*4.0*(double)(1<<30);
     116  d += (nt->low&0xFFF00000);
     117  d *= 1.0e-7;
     118 
     119  /* now adjust by 369 years to make the secs since 1970 */
     120  d -= TIME_FIXUP_CONSTANT;
     121 
     122  if (d <= l_time_min)
     123    return (l_time_min);
     124 
     125  if (d >= l_time_max)
     126    return (l_time_max);
     127 
     128  ret = (time_t)(d+0.5);
     129 
     130  /* this takes us from kludge-GMT to real GMT */
     131  /* XXX: This was removed due to difficult dependency requirements. 
     132   *      So far, times appear to be correct without this adjustment, but
     133   *      that may be proven wrong with adequate testing.
     134   */
     135  /*
     136    ret -= get_serverzone();
     137    ret += LocTimeDiff(ret);
     138  */
     139
     140  return(ret);
     141}
    129142
    130143/* End of stuff from lib/time.c */
     
    138151bool prs_grow(prs_struct *ps, uint32 extra_space)
    139152{
    140         uint32 new_size;
    141         char *new_data;
    142 
    143         ps->grow_size = MAX(ps->grow_size, ps->data_offset + extra_space);
    144 
    145         if(ps->data_offset + extra_space <= ps->buffer_size)
    146                 return true;
    147 
    148         /*
    149         * We cannot grow the buffer if we're not reading
    150         * into the prs_struct, or if we don't own the memory.
    151         */
    152 
    153         if(ps->io || !ps->is_dynamic) {
    154                 return false;
    155         }
    156        
    157         /*
    158          * Decide how much extra space we really need.
    159          */
    160 
    161         extra_space -= (ps->buffer_size - ps->data_offset);
    162         if(ps->buffer_size == 0) {
    163                 /*
    164                  * Ensure we have at least a PDU's length, or extra_space, whichever
    165                  * is greater.
    166                  */
    167 
    168                 new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
    169 
    170                 if((new_data = zalloc(new_size)) == NULL) {
    171                         return false;
    172                 }
    173                 memset(new_data, '\0', (size_t)new_size );
    174         } else {
    175                 /*
    176                 * If the current buffer size is bigger than the space needed, just
    177                 * double it, else add extra_space.
    178                 */
    179                 new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);               
    180 
    181                 if ((new_data = (char*)realloc(ps->data_p, new_size)) == NULL) {
    182                         return false;
    183                 }
    184 
    185                 memset(&new_data[ps->buffer_size], '\0', (size_t)(new_size - ps->buffer_size));
    186         }
    187         ps->buffer_size = new_size;
    188         ps->data_p = new_data;
    189 
    190         return true;
     153  uint32 new_size;
     154  char *new_data;
     155 
     156  ps->grow_size = MAX(ps->grow_size, ps->data_offset + extra_space);
     157 
     158  if(ps->data_offset + extra_space <= ps->buffer_size)
     159    return true;
     160 
     161  /*
     162  * We cannot grow the buffer if we're not reading
     163  * into the prs_struct, or if we don't own the memory.
     164  */
     165 
     166  if(ps->io || !ps->is_dynamic)
     167    return false;
     168 
     169  /*
     170   * Decide how much extra space we really need.
     171   */
     172  extra_space -= (ps->buffer_size - ps->data_offset);
     173  if(ps->buffer_size == 0)
     174  {
     175    /*
     176     * Ensure we have at least a PDU's length, or extra_space,
     177     * whichever is greater.
     178     */ 
     179    new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
     180   
     181    if((new_data = zalloc(new_size)) == NULL)
     182      return false;
     183
     184    memset(new_data, '\0', (size_t)new_size );
     185  }
     186  else
     187  {
     188    /*
     189    * If the current buffer size is bigger than the space needed, just
     190    * double it, else add extra_space.
     191    */
     192    new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);           
     193   
     194    if ((new_data = (char*)realloc(ps->data_p, new_size)) == NULL)
     195      return false;
     196   
     197    memset(&new_data[ps->buffer_size], '\0',
     198          (size_t)(new_size - ps->buffer_size));
     199  }
     200  ps->buffer_size = new_size;
     201  ps->data_p = new_data;
     202 
     203  return true;
    191204}
    192205
     
    198211bool prs_align(prs_struct *ps)
    199212{
    200         uint32 mod = ps->data_offset & (ps->align-1);
    201 
    202         if (ps->align != 0 && mod != 0) {
    203                 uint32 extra_space = (ps->align - mod);
    204                 if(!prs_grow(ps, extra_space))
    205                         return false;
    206                 memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space);
    207                 ps->data_offset += extra_space;
    208         }
    209 
    210         return true;
     213  uint32 mod = ps->data_offset & (ps->align-1);
     214 
     215  if (ps->align != 0 && mod != 0)
     216  {
     217    uint32 extra_space = (ps->align - mod);
     218    if(!prs_grow(ps, extra_space))
     219      return false;
     220    memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space);
     221    ps->data_offset += extra_space;
     222  }
     223 
     224  return true;
    211225}
    212226
     
    233247  ps->mem_ctx = ctx;
    234248 
    235   if (size != 0) {
     249  if (size != 0)
     250  {
    236251    ps->buffer_size = size;
    237     if((ps->data_p = (char *)zalloc((size_t)size)) == NULL) {
    238       return false;
    239     }
     252    if((ps->data_p = (char *)zalloc((size_t)size)) == NULL)
     253      return false;
     254
    240255    memset(ps->data_p, '\0', (size_t)size);
    241256    ps->is_dynamic = true; /* We own this memory. */
     
    248263char *prs_mem_get(prs_struct *ps, uint32 extra_size)
    249264{
    250         if(ps->io) {
    251                 /*
    252                  * If reading, ensure that we can read the requested size item.
    253                  */
    254                 if (ps->data_offset + extra_size > ps->buffer_size) {
    255                         return NULL;
    256                 }
    257         } else {
    258                 /*
    259                  * Writing - grow the buffer if needed.
    260                  */
    261                 if(!prs_grow(ps, extra_size))
    262                         return NULL;
    263         }
    264         return &ps->data_p[ps->data_offset];
     265  if(ps->io)
     266  {
     267    /*
     268     * If reading, ensure that we can read the requested size item.
     269     */
     270    if (ps->data_offset + extra_size > ps->buffer_size)
     271      return NULL;
     272  }
     273  else
     274  {
     275    /*
     276     * Writing - grow the buffer if needed.
     277     */
     278    if(!prs_grow(ps, extra_size))
     279      return NULL;
     280  }
     281  return &ps->data_p[ps->data_offset];
    265282}
    266283
     
    271288bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32 *data32)
    272289{
    273         char *q = prs_mem_get(ps, sizeof(uint32));
    274         if (q == NULL)
    275                 return false;
    276 
    277         if (ps->io) {
    278                 if (ps->bigendian_data)
    279                         *data32 = RIVAL(q,0);
    280                 else
    281                         *data32 = IVAL(q,0);
    282         } else {
    283                 if (ps->bigendian_data)
    284                         RSIVAL(q,0,*data32);
    285                 else
    286                         SIVAL(q,0,*data32);
    287         }
    288 
    289         ps->data_offset += sizeof(uint32);
    290 
    291         return true;
     290  char *q = prs_mem_get(ps, sizeof(uint32));
     291  if (q == NULL)
     292    return false;
     293 
     294  if (ps->io)
     295  {
     296    if (ps->bigendian_data)
     297      *data32 = RIVAL(q,0);
     298    else
     299      *data32 = IVAL(q,0);
     300  }
     301  else
     302  {
     303    if (ps->bigendian_data)
     304      RSIVAL(q,0,*data32);
     305    else
     306      SIVAL(q,0,*data32);
     307  }
     308  ps->data_offset += sizeof(uint32);
     309 
     310  return true;
    292311}
    293312
     
    299318                 int depth, uint32 *data32s, int len)
    300319{
    301         int i;
    302         char *q = prs_mem_get(ps, len * sizeof(uint32));
    303         if (q == NULL)
    304                 return false;
    305 
    306         if (ps->io) {
    307                 if (ps->bigendian_data) {
    308                         for (i = 0; i < len; i++)
    309                                 data32s[i] = RIVAL(q, 4*i);
    310                 } else {
    311                         for (i = 0; i < len; i++)
    312                                 data32s[i] = IVAL(q, 4*i);
    313                 }
    314         } else {
    315                 if (ps->bigendian_data) {
    316                         for (i = 0; i < len; i++)
    317                                 RSIVAL(q, 4*i, data32s[i]);
    318                 } else {
    319                         for (i = 0; i < len; i++)
    320                                 SIVAL(q, 4*i, data32s[i]);
    321                 }
    322         }
    323 
    324         ps->data_offset += (len * sizeof(uint32));
    325 
    326         return true;
     320  int i;
     321  char *q = prs_mem_get(ps, len * sizeof(uint32));
     322  if (q == NULL)
     323    return false;
     324 
     325  if (ps->io)
     326  {
     327    if (ps->bigendian_data)
     328    {
     329      for (i = 0; i < len; i++)
     330        data32s[i] = RIVAL(q, 4*i);
     331    }
     332    else
     333    {
     334      for (i = 0; i < len; i++)
     335        data32s[i] = IVAL(q, 4*i);
     336    }
     337  }
     338  else
     339  {
     340    if (ps->bigendian_data)
     341    {
     342      for (i = 0; i < len; i++)
     343        RSIVAL(q, 4*i, data32s[i]);
     344    }
     345    else
     346    {
     347      for (i = 0; i < len; i++)
     348        SIVAL(q, 4*i, data32s[i]);
     349    }
     350  }
     351  ps->data_offset += (len * sizeof(uint32));
     352 
     353  return true;
    327354}
    328355
     
    333360bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16 *data16)
    334361{
    335         char *q = prs_mem_get(ps, sizeof(uint16));
    336         if (q == NULL)
    337                 return false;
    338 
    339         if (ps->io) {
    340                 if (ps->bigendian_data)
    341                         *data16 = RSVAL(q,0);
    342                 else
    343                         *data16 = SVAL(q,0);
    344         } else {
    345                 if (ps->bigendian_data)
    346                         RSSVAL(q,0,*data16);
    347                 else
    348                         SSVAL(q,0,*data16);
    349         }
    350 
    351 
    352         ps->data_offset += sizeof(uint16);
    353 
    354         return true;
     362  char *q = prs_mem_get(ps, sizeof(uint16));
     363  if (q == NULL)
     364    return false;
     365 
     366  if (ps->io)
     367  {
     368    if (ps->bigendian_data)
     369      *data16 = RSVAL(q,0);
     370    else
     371      *data16 = SVAL(q,0);
     372  }
     373  else
     374  {
     375    if (ps->bigendian_data)
     376      RSSVAL(q,0,*data16);
     377    else
     378      SSVAL(q,0,*data16);
     379  }
     380  ps->data_offset += sizeof(uint16);
     381 
     382  return true;
    355383}
    356384
     
    363391                    uint16 *data16, uint32 *offset)
    364392{
    365         *offset = ps->data_offset;
    366         if (ps->io) {
    367                 /* reading. */
    368                 return prs_uint16(name, ps, depth, data16);
    369         } else {
    370                 char *q = prs_mem_get(ps, sizeof(uint16));
    371                 if(q ==NULL)
    372                         return false;
    373                 ps->data_offset += sizeof(uint16);
    374         }
    375         return true;
     393  *offset = ps->data_offset;
     394  if (ps->io)
     395  {
     396    /* reading. */
     397    return prs_uint16(name, ps, depth, data16);
     398  }
     399  else
     400  {
     401    char *q = prs_mem_get(ps, sizeof(uint16));
     402    if(q ==NULL)
     403      return false;
     404    ps->data_offset += sizeof(uint16);
     405  }
     406  return true;
    376407}
    377408
     
    384415                     uint16 *data16, uint32 ptr_uint16, uint32 start_offset)
    385416{
    386         if (!ps->io) {
    387                 /*
    388                  * Writing - temporarily move the offset pointer.
    389                  */
    390                 uint16 data_size = ps->data_offset - start_offset;
    391                 uint32 old_offset = ps->data_offset;
    392 
    393                 ps->data_offset = ptr_uint16;
    394                 if(!prs_uint16(name, ps, depth, &data_size)) {
    395                         ps->data_offset = old_offset;
    396                         return false;
    397                 }
    398                 ps->data_offset = old_offset;
    399         } else {
    400                 ps->data_offset = start_offset + (uint32)(*data16);
    401         }
    402         return true;
     417  if (!ps->io)
     418  {
     419    /*
     420     * Writing - temporarily move the offset pointer.
     421     */
     422    uint16 data_size = ps->data_offset - start_offset;
     423    uint32 old_offset = ps->data_offset;
     424   
     425    ps->data_offset = ptr_uint16;
     426    if(!prs_uint16(name, ps, depth, &data_size))
     427    {
     428      ps->data_offset = old_offset;
     429      return false;
     430    }
     431    ps->data_offset = old_offset;
     432  }
     433  else
     434    ps->data_offset = start_offset + (uint32)(*data16);
     435
     436  return true;
    403437}
    404438
     
    409443bool prs_uint8(const char *name, prs_struct *ps, int depth, uint8 *data8)
    410444{
    411         char *q = prs_mem_get(ps, 1);
    412         if (q == NULL)
    413                 return false;
    414 
    415     if (ps->io)
    416                 *data8 = CVAL(q,0);
    417         else
    418                 SCVAL(q,0,*data8);
    419 
    420         ps->data_offset += 1;
    421 
    422         return true;
     445  char *q = prs_mem_get(ps, 1);
     446  if (q == NULL)
     447    return false;
     448 
     449  if (ps->io)
     450    *data8 = CVAL(q,0);
     451  else
     452    SCVAL(q,0,*data8);
     453 
     454  ps->data_offset += 1;
     455 
     456  return true;
    423457}
    424458
     
    430464                uint8* data8s, int len)
    431465{
    432         int i;
    433         char *q = prs_mem_get(ps, len);
    434         if (q == NULL)
    435                 return false;
    436 
    437         if (ps->io) {
    438                 for (i = 0; i < len; i++)
    439                         data8s[i] = CVAL(q,i);
    440         } else {
    441                 for (i = 0; i < len; i++)
    442                         SCVAL(q, i, data8s[i]);
    443         }
    444 
    445         ps->data_offset += len;
    446 
    447         return true;
     466  int i;
     467  char *q = prs_mem_get(ps, len);
     468  if (q == NULL)
     469    return false;
     470 
     471  if (ps->io)
     472  {
     473    for (i = 0; i < len; i++)
     474      data8s[i] = CVAL(q,i);
     475  }
     476  else
     477  {
     478    for (i = 0; i < len; i++)
     479      SCVAL(q, i, data8s[i]);
     480  }
     481 
     482  ps->data_offset += len;
     483 
     484  return true;
    448485}
    449486
     
    454491bool prs_set_offset(prs_struct *ps, uint32 offset)
    455492{
    456         if(offset <= ps->data_offset) {
    457                 ps->data_offset = offset;
    458                 return true;
    459         }
    460 
    461         if(!prs_grow(ps, offset - ps->data_offset))
    462                 return false;
    463 
    464         ps->data_offset = offset;
    465         return true;
     493  if(offset <= ps->data_offset)
     494  {
     495    ps->data_offset = offset;
     496    return true;
     497  }
     498 
     499  if(!prs_grow(ps, offset - ps->data_offset))
     500    return false;
     501 
     502  ps->data_offset = offset;
     503  return true;
    466504}
    467505
     
    476514                 prs_struct *ps, int depth)
    477515{
    478         if (uuid == NULL)
    479                 return false;
    480         depth++;
    481 
    482         if(!prs_uint32 ("data   ", ps, depth, &uuid->time_low))
    483                 return false;
    484         if(!prs_uint16 ("data   ", ps, depth, &uuid->time_mid))
    485                 return false;
    486         if(!prs_uint16 ("data   ", ps, depth, &uuid->time_hi_and_version))
    487                 return false;
    488 
    489         if(!prs_uint8s (false, "data   ", ps, depth, uuid->clock_seq, sizeof(uuid->clock_seq)))
    490                 return false;
    491         if(!prs_uint8s (false, "data   ", ps, depth, uuid->node, sizeof(uuid->node)))
    492                 return false;
    493 
    494         return true;
     516  if (uuid == NULL)
     517    return false;
     518  depth++;
     519 
     520  if(!prs_uint32 ("data   ", ps, depth, &uuid->time_low))
     521    return false;
     522  if(!prs_uint16 ("data   ", ps, depth, &uuid->time_mid))
     523    return false;
     524  if(!prs_uint16 ("data   ", ps, depth, &uuid->time_hi_and_version))
     525    return false;
     526 
     527  if(!prs_uint8s (false, "data   ", ps, depth,
     528                  uuid->clock_seq, sizeof(uuid->clock_seq)))
     529    return false;
     530
     531  if(!prs_uint8s (false, "data   ", ps, depth, uuid->node, sizeof(uuid->node)))
     532    return false;
     533 
     534  return true;
    495535}
    496536
     
    501541bool smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth)
    502542{
    503         if (nttime == NULL)
    504                 return false;
    505         depth++;
    506 
    507         if(!prs_align(ps))
    508                 return false;
     543  if (nttime == NULL)
     544    return false;
     545  depth++;
     546
     547  if(!prs_align(ps))
     548    return false;
    509549       
    510         if(!prs_uint32("low ", ps, depth, &nttime->low)) /* low part */
    511                 return false;
    512         if(!prs_uint32("high", ps, depth, &nttime->high)) /* high part */
    513                 return false;
    514 
    515         return true;
     550  if(!prs_uint32("low ", ps, depth, &nttime->low)) /* low part */
     551    return false;
     552  if(!prs_uint32("high", ps, depth, &nttime->high)) /* high part */
     553    return false;
     554
     555  return true;
    516556}
    517557
     
    522562bool smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth)
    523563{
    524         int i;
    525 
    526         if (sid == NULL)
    527                 return false;
    528         depth++;
    529 
    530         if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num))
    531                 return false;
    532 
    533         if(!prs_uint8 ("num_auths  ", ps, depth, &sid->num_auths))
    534                 return false;
    535 
    536         for (i = 0; i < 6; i++)
    537         {
    538                 fstring tmp;
    539                 snprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i);
    540                 if(!prs_uint8 (tmp, ps, depth, &sid->id_auth[i]))
    541                         return false;
    542         }
    543 
    544         /* oops! XXXX should really issue a warning here... */
    545         if (sid->num_auths > MAXSUBAUTHS)
    546                 sid->num_auths = MAXSUBAUTHS;
    547 
    548         if(!prs_uint32s(false, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths))
    549                 return false;
    550 
    551         return true;
     564  int i;
     565
     566  if (sid == NULL)
     567    return false;
     568  depth++;
     569
     570  if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num))
     571    return false;
     572
     573  if(!prs_uint8 ("num_auths  ", ps, depth, &sid->num_auths))
     574    return false;
     575
     576  for (i = 0; i < 6; i++)
     577  {
     578    fstring tmp;
     579    snprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i);
     580    if(!prs_uint8 (tmp, ps, depth, &sid->id_auth[i]))
     581      return false;
     582  }
     583
     584  /* oops! XXXX should really issue a warning here... */
     585  if (sid->num_auths > MAXSUBAUTHS)
     586    sid->num_auths = MAXSUBAUTHS;
     587
     588  if(!prs_uint32s(false, "sub_auths ", ps, depth,
     589                  sid->sub_auths, sid->num_auths))
     590  { return false; }
     591
     592  return true;
    552593}
    553594
     
    561602size_t sid_size(const DOM_SID *sid)
    562603{
    563         if (sid == NULL)
    564                 return 0;
    565 
    566         return sid->num_auths * sizeof(uint32) + 8;
     604  if (sid == NULL)
     605    return 0;
     606
     607  return sid->num_auths * sizeof(uint32) + 8;
    567608}
    568609
     
    573614int sid_compare_auth(const DOM_SID *sid1, const DOM_SID *sid2)
    574615{
    575         int i;
    576 
    577         if (sid1 == sid2)
    578                 return 0;
    579         if (!sid1)
    580                 return -1;
    581         if (!sid2)
    582                 return 1;
    583 
    584         if (sid1->sid_rev_num != sid2->sid_rev_num)
    585                 return sid1->sid_rev_num - sid2->sid_rev_num;
    586 
    587         for (i = 0; i < 6; i++)
    588                 if (sid1->id_auth[i] != sid2->id_auth[i])
    589                         return sid1->id_auth[i] - sid2->id_auth[i];
    590 
    591         return 0;
     616  int i;
     617
     618  if (sid1 == sid2)
     619    return 0;
     620  if (!sid1)
     621    return -1;
     622  if (!sid2)
     623    return 1;
     624
     625  if (sid1->sid_rev_num != sid2->sid_rev_num)
     626    return sid1->sid_rev_num - sid2->sid_rev_num;
     627
     628  for (i = 0; i < 6; i++)
     629    if (sid1->id_auth[i] != sid2->id_auth[i])
     630      return sid1->id_auth[i] - sid2->id_auth[i];
     631
     632  return 0;
    592633}
    593634
     
    598639int sid_compare(const DOM_SID *sid1, const DOM_SID *sid2)
    599640{
    600         int i;
    601 
    602         if (sid1 == sid2)
    603                 return 0;
    604         if (!sid1)
    605                 return -1;
    606         if (!sid2)
    607                 return 1;
    608 
    609         /* Compare most likely different rids, first: i.e start at end */
    610         if (sid1->num_auths != sid2->num_auths)
    611                 return sid1->num_auths - sid2->num_auths;
    612 
    613         for (i = sid1->num_auths-1; i >= 0; --i)
    614                 if (sid1->sub_auths[i] != sid2->sub_auths[i])
    615                         return sid1->sub_auths[i] - sid2->sub_auths[i];
    616 
    617         return sid_compare_auth(sid1, sid2);
     641  int i;
     642
     643  if (sid1 == sid2)
     644    return 0;
     645  if (!sid1)
     646    return -1;
     647  if (!sid2)
     648    return 1;
     649
     650  /* Compare most likely different rids, first: i.e start at end */
     651  if (sid1->num_auths != sid2->num_auths)
     652    return sid1->num_auths - sid2->num_auths;
     653
     654  for (i = sid1->num_auths-1; i >= 0; --i)
     655    if (sid1->sub_auths[i] != sid2->sub_auths[i])
     656      return sid1->sub_auths[i] - sid2->sub_auths[i];
     657
     658  return sid_compare_auth(sid1, sid2);
    618659}
    619660
     
    624665bool sid_equal(const DOM_SID *sid1, const DOM_SID *sid2)
    625666{
    626         return sid_compare(sid1, sid2) == 0;
     667  return sid_compare(sid1, sid2) == 0;
    627668}
    628669
     
    637678bool sec_ace_object(uint8 type)
    638679{
    639         if (type == SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT ||
    640             type == SEC_ACE_TYPE_ACCESS_DENIED_OBJECT ||
    641             type == SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT ||
    642             type == SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT) {
    643                 return true;
    644         }
    645         return false;
     680  if (type == SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT ||
     681      type == SEC_ACE_TYPE_ACCESS_DENIED_OBJECT ||
     682      type == SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT ||
     683      type == SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT) {
     684    return true;
     685  }
     686  return false;
    646687}
    647688
     
    655696bool sec_io_access(const char *desc, SEC_ACCESS *t, prs_struct *ps, int depth)
    656697{
    657         if (t == NULL)
    658                 return false;
    659 
    660         depth++;
     698  if (t == NULL)
     699    return false;
     700
     701  depth++;
    661702       
    662         if(!prs_uint32("mask", ps, depth, &t->mask))
    663                 return false;
    664 
    665         return true;
     703  if(!prs_uint32("mask", ps, depth, &t->mask))
     704    return false;
     705
     706  return true;
    666707}
    667708
     
    672713bool sec_io_ace(const char *desc, SEC_ACE *psa, prs_struct *ps, int depth)
    673714{
    674         uint32 old_offset;
    675         uint32 offset_ace_size;
    676 
    677         if (psa == NULL)
    678                 return false;
    679 
    680         depth++;
     715  uint32 old_offset;
     716  uint32 offset_ace_size;
     717
     718  if (psa == NULL)
     719    return false;
     720
     721  depth++;
    681722       
    682         old_offset = ps->data_offset;
    683 
    684         if(!prs_uint8("type ", ps, depth, &psa->type))
    685                 return false;
    686 
    687         if(!prs_uint8("flags", ps, depth, &psa->flags))
    688                 return false;
    689 
    690         if(!prs_uint16_pre("size ", ps, depth, &psa->size, &offset_ace_size))
    691                 return false;
    692 
    693         if(!sec_io_access("info ", &psa->info, ps, depth))
    694                 return false;
    695 
    696         /* check whether object access is present */
    697         if (!sec_ace_object(psa->type)) {
    698                 if (!smb_io_dom_sid("trustee  ", &psa->trustee , ps, depth))
    699                         return false;
    700         } else {
    701                 if (!prs_uint32("obj_flags", ps, depth, &psa->obj_flags))
    702                         return false;
    703 
    704                 if (psa->obj_flags & SEC_ACE_OBJECT_PRESENT)
    705                         if (!smb_io_uuid("obj_guid", &psa->obj_guid, ps,depth))
    706                                 return false;
    707 
    708                 if (psa->obj_flags & SEC_ACE_OBJECT_INHERITED_PRESENT)
    709                         if (!smb_io_uuid("inh_guid", &psa->inh_guid, ps,depth))
    710                                 return false;
    711 
    712                 if(!smb_io_dom_sid("trustee  ", &psa->trustee , ps, depth))
    713                         return false;
    714         }
    715 
    716         /* Theorectically an ACE can have a size greater than the
    717            sum of its components. When marshalling, pad with extra null bytes up to the
    718            correct size. */
    719 
    720         if (!ps->io && (psa->size > ps->data_offset - old_offset)) {
    721                 uint32 extra_len = psa->size - (ps->data_offset - old_offset);
    722                 uint32 i;
    723                 uint8 c = 0;
    724 
    725                 for (i = 0; i < extra_len; i++) {
    726                         if (!prs_uint8("ace extra space", ps, depth, &c))
    727                                 return false;
    728                 }
    729         }
    730 
    731         if(!prs_uint16_post("size ", ps, depth, &psa->size, offset_ace_size, old_offset))
    732                 return false;
    733 
    734         return true;
     723  old_offset = ps->data_offset;
     724
     725  if(!prs_uint8("type ", ps, depth, &psa->type))
     726    return false;
     727
     728  if(!prs_uint8("flags", ps, depth, &psa->flags))
     729    return false;
     730
     731  if(!prs_uint16_pre("size ", ps, depth, &psa->size, &offset_ace_size))
     732    return false;
     733
     734  if(!sec_io_access("info ", &psa->info, ps, depth))
     735    return false;
     736
     737  /* check whether object access is present */
     738  if (!sec_ace_object(psa->type))
     739  {
     740    if (!smb_io_dom_sid("trustee  ", &psa->trustee , ps, depth))
     741      return false;
     742  }
     743  else
     744  {
     745    if (!prs_uint32("obj_flags", ps, depth, &psa->obj_flags))
     746      return false;
     747
     748    if (psa->obj_flags & SEC_ACE_OBJECT_PRESENT)
     749      if (!smb_io_uuid("obj_guid", &psa->obj_guid, ps,depth))
     750        return false;
     751
     752    if (psa->obj_flags & SEC_ACE_OBJECT_INHERITED_PRESENT)
     753      if (!smb_io_uuid("inh_guid", &psa->inh_guid, ps,depth))
     754        return false;
     755
     756    if(!smb_io_dom_sid("trustee  ", &psa->trustee , ps, depth))
     757      return false;
     758  }
     759
     760  /* Theorectically an ACE can have a size greater than the
     761   * sum of its components. When marshalling, pad with extra null bytes
     762   * up to the
     763   * correct size.
     764   */
     765  if (!ps->io && (psa->size > ps->data_offset - old_offset))
     766  {
     767    uint32 extra_len = psa->size - (ps->data_offset - old_offset);
     768    uint32 i;
     769    uint8 c = 0;
     770
     771    for (i = 0; i < extra_len; i++)
     772    {
     773      if (!prs_uint8("ace extra space", ps, depth, &c))
     774        return false;
     775    }
     776  }
     777
     778  if(!prs_uint16_post("size ", ps, depth, &psa->size,
     779                      offset_ace_size, old_offset))
     780  { return false; }
     781
     782  return true;
    735783}
    736784
     
    744792bool sec_io_acl(const char *desc, SEC_ACL **ppsa, prs_struct *ps, int depth)
    745793{
    746         unsigned int i;
    747         uint32 old_offset;
    748         uint32 offset_acl_size;
    749         SEC_ACL *psa;
    750 
    751         /*
    752          * Note that the size is always a multiple of 4 bytes due to the
    753          * nature of the data structure.  Therefore the prs_align() calls
    754          * have been removed as they through us off when doing two-layer
    755          * marshalling such as in the printing code (RPC_BUFFER).  --jerry
    756          */
    757 
    758         if (ppsa == NULL)
    759                 return false;
    760 
    761         psa = *ppsa;
    762 
    763         if(ps->io && psa == NULL) {
    764                 /*
    765                  * This is a read and we must allocate the stuct to read into.
    766                  */
    767           if((psa = (SEC_ACL*)zalloc(sizeof(SEC_ACL))) == NULL)
    768                         return false;
    769                 *ppsa = psa;
    770         }
    771 
    772         depth++;
     794  unsigned int i;
     795  uint32 old_offset;
     796  uint32 offset_acl_size;
     797  SEC_ACL *psa;
     798
     799  /*
     800   * Note that the size is always a multiple of 4 bytes due to the
     801   * nature of the data structure.  Therefore the prs_align() calls
     802   * have been removed as they through us off when doing two-layer
     803   * marshalling such as in the printing code (RPC_BUFFER).  --jerry
     804   */
     805
     806  if (ppsa == NULL)
     807    return false;
     808
     809  psa = *ppsa;
     810
     811  if(ps->io && psa == NULL)
     812  {
     813    /*
     814     * This is a read and we must allocate the stuct to read into.
     815     */
     816    if((psa = (SEC_ACL*)zalloc(sizeof(SEC_ACL))) == NULL)
     817      return false;
     818    *ppsa = psa;
     819  }
     820
     821  depth++;
    773822       
    774         old_offset = ps->data_offset;
    775 
    776         if(!prs_uint16("revision", ps, depth, &psa->revision))
    777                 return false;
    778 
    779         if(!prs_uint16_pre("size     ", ps, depth, &psa->size, &offset_acl_size))
    780                 return false;
    781 
    782         if(!prs_uint32("num_aces ", ps, depth, &psa->num_aces))
    783                 return false;
    784 
    785         if (ps->io) {
    786                 /*
    787                  * Even if the num_aces is zero, allocate memory as there's a difference
    788                  * between a non-present DACL (allow all access) and a DACL with no ACE's
    789                  * (allow no access).
    790                  */
    791           if((psa->ace = (SEC_ACE*)zcalloc(sizeof(SEC_ACE), psa->num_aces+1)) == NULL)
    792                         return false;
    793         }
    794 
    795         for (i = 0; i < psa->num_aces; i++) {
    796                 fstring tmp;
    797                 snprintf(tmp, sizeof(tmp)-1, "ace_list[%02d]: ", i);
    798                 if(!sec_io_ace(tmp, &psa->ace[i], ps, depth))
    799                         return false;
    800         }
    801 
    802         /* Theorectically an ACL can have a size greater than the
    803            sum of its components. When marshalling, pad with extra null bytes up to the
    804            correct size. */
    805 
    806         if (!ps->io && (psa->size > ps->data_offset - old_offset)) {
    807                 uint32 extra_len = psa->size - (ps->data_offset - old_offset);
    808                 uint8 c = 0;
    809 
    810                 for (i = 0; i < extra_len; i++) {
    811                         if (!prs_uint8("acl extra space", ps, depth, &c))
    812                                 return false;
    813                 }
    814         }
    815 
    816         if(!prs_uint16_post("size     ", ps, depth, &psa->size, offset_acl_size, old_offset))
    817                 return false;
    818 
    819         return true;
     823  old_offset = ps->data_offset;
     824
     825  if(!prs_uint16("revision", ps, depth, &psa->revision))
     826    return false;
     827
     828  if(!prs_uint16_pre("size     ", ps, depth, &psa->size, &offset_acl_size))
     829    return false;
     830
     831  if(!prs_uint32("num_aces ", ps, depth, &psa->num_aces))
     832    return false;
     833
     834  if (ps->io)
     835  {
     836    /*
     837     * Even if the num_aces is zero, allocate memory as there's a difference
     838     * between a non-present DACL (allow all access) and a DACL with no ACE's
     839     * (allow no access).
     840     */
     841    if((psa->ace = (SEC_ACE*)zcalloc(sizeof(SEC_ACE), psa->num_aces+1)) == NULL)
     842      return false;
     843  }
     844
     845  for (i = 0; i < psa->num_aces; i++)
     846  {
     847    fstring tmp;
     848    snprintf(tmp, sizeof(tmp)-1, "ace_list[%02d]: ", i);
     849    if(!sec_io_ace(tmp, &psa->ace[i], ps, depth))
     850      return false;
     851  }
     852
     853  /* Theoretically an ACL can have a size greater than the
     854   *  sum of its components. When marshalling, pad with extra null
     855   *  bytes up to the
     856   *  correct size.
     857   */
     858  if (!ps->io && (psa->size > ps->data_offset - old_offset))
     859  {
     860    uint32 extra_len = psa->size - (ps->data_offset - old_offset);
     861    uint8 c = 0;
     862
     863    for (i = 0; i < extra_len; i++)
     864    {
     865      if (!prs_uint8("acl extra space", ps, depth, &c))
     866        return false;
     867    }
     868  }
     869
     870  if(!prs_uint16_post("size     ", ps, depth, &psa->size,
     871                      offset_acl_size, old_offset))
     872  { return false; }
     873
     874  return true;
    820875}
    821876
     
    827882bool sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
    828883{
    829         uint32 old_offset;
    830         uint32 max_offset = 0; /* after we're done, move offset to end */
    831         uint32 tmp_offset = 0;
    832 
    833         SEC_DESC *psd;
    834 
    835         if (ppsd == NULL)
    836                 return false;
    837 
    838         psd = *ppsd;
    839 
    840         if (psd == NULL) {
    841                 if(ps->io) {
    842                   if((psd = (SEC_DESC*)zalloc(sizeof(SEC_DESC))) == NULL)
    843                                 return false;
    844                         *ppsd = psd;
    845                 } else {
    846                         /* Marshalling - just ignore. */
    847                         return true;
    848                 }
    849         }
    850 
    851         depth++;
    852 
    853         /* start of security descriptor stored for back-calc offset purposes */
    854         old_offset = ps->data_offset;
    855 
    856         if(!prs_uint16("revision ", ps, depth, &psd->revision))
    857                 return false;
    858 
    859         if(!prs_uint16("type     ", ps, depth, &psd->type))
    860                 return false;
    861 
    862         if (!ps->io) {
    863                 uint32 offset = SEC_DESC_HEADER_SIZE;
    864 
    865                 /*
    866                  * Work out the offsets here, as we write it out.
    867                  */
    868 
    869                 if (psd->sacl != NULL) {
    870                         psd->off_sacl = offset;
    871                         offset += psd->sacl->size;
    872                 } else {
    873                         psd->off_sacl = 0;
    874                 }
    875 
    876                 if (psd->dacl != NULL) {
    877                         psd->off_dacl = offset;
    878                         offset += psd->dacl->size;
    879                 } else {
    880                         psd->off_dacl = 0;
    881                 }
    882 
    883                 if (psd->owner_sid != NULL) {
    884                         psd->off_owner_sid = offset;
    885                         offset += sid_size(psd->owner_sid);
    886                 } else {
    887                         psd->off_owner_sid = 0;
    888                 }
    889 
    890                 if (psd->grp_sid != NULL) {
    891                         psd->off_grp_sid = offset;
    892                         offset += sid_size(psd->grp_sid);
    893                 } else {
    894                         psd->off_grp_sid = 0;
    895                 }
    896         }
    897 
    898         if(!prs_uint32("off_owner_sid", ps, depth, &psd->off_owner_sid))
    899                 return false;
    900 
    901         if(!prs_uint32("off_grp_sid  ", ps, depth, &psd->off_grp_sid))
    902                 return false;
    903 
    904         if(!prs_uint32("off_sacl     ", ps, depth, &psd->off_sacl))
    905                 return false;
    906 
    907         if(!prs_uint32("off_dacl     ", ps, depth, &psd->off_dacl))
    908                 return false;
    909 
    910         max_offset = MAX(max_offset, ps->data_offset);
    911 
    912         if (psd->off_owner_sid != 0) {
    913 
    914                 tmp_offset = ps->data_offset;
    915                 if(!prs_set_offset(ps, old_offset + psd->off_owner_sid))
    916                         return false;
    917 
    918                 if (ps->io) {
    919                         /* reading */
    920                   if((psd->owner_sid = (DOM_SID*)zalloc(sizeof(DOM_SID))) == NULL)
    921                                 return false;
    922                 }
    923 
    924                 if(!smb_io_dom_sid("owner_sid ", psd->owner_sid , ps, depth))
    925                         return false;
    926 
    927                 max_offset = MAX(max_offset, ps->data_offset);
    928 
    929                 if (!prs_set_offset(ps,tmp_offset))
    930                         return false;
    931         }
    932 
    933         if (psd->off_grp_sid != 0) {
    934 
    935                 tmp_offset = ps->data_offset;
    936                 if(!prs_set_offset(ps, old_offset + psd->off_grp_sid))
    937                         return false;
    938 
    939                 if (ps->io) {
    940                         /* reading */
    941                         if((psd->grp_sid = (DOM_SID*)zalloc(sizeof(DOM_SID))) == NULL)
    942                                 return false;
    943                 }
    944 
    945                 if(!smb_io_dom_sid("grp_sid", psd->grp_sid, ps, depth))
    946                         return false;
     884  uint32 old_offset;
     885  uint32 max_offset = 0; /* after we're done, move offset to end */
     886  uint32 tmp_offset = 0;
     887
     888  SEC_DESC *psd;
     889
     890  if (ppsd == NULL)
     891    return false;
     892
     893  psd = *ppsd;
     894
     895  if (psd == NULL)
     896  {
     897    if(ps->io)
     898    {
     899      if((psd = (SEC_DESC*)zalloc(sizeof(SEC_DESC))) == NULL)
     900        return false;
     901      *ppsd = psd;
     902    }
     903    else
     904    {
     905      /* Marshalling - just ignore. */
     906      return true;
     907    }
     908  }
     909
     910  depth++;
     911
     912  /* start of security descriptor stored for back-calc offset purposes */
     913  old_offset = ps->data_offset;
     914
     915  if(!prs_uint16("revision ", ps, depth, &psd->revision))
     916    return false;
     917
     918  if(!prs_uint16("type     ", ps, depth, &psd->type))
     919    return false;
     920
     921  if (!ps->io)
     922  {
     923    uint32 offset = SEC_DESC_HEADER_SIZE;
     924
     925    /*
     926     * Work out the offsets here, as we write it out.
     927     */
     928
     929    if (psd->sacl != NULL)
     930    {
     931      psd->off_sacl = offset;
     932      offset += psd->sacl->size;
     933    }
     934    else
     935      psd->off_sacl = 0;
     936
     937    if (psd->dacl != NULL)
     938    {
     939      psd->off_dacl = offset;
     940      offset += psd->dacl->size;
     941    }
     942    else
     943      psd->off_dacl = 0;
     944
     945    if (psd->owner_sid != NULL)
     946    {
     947      psd->off_owner_sid = offset;
     948      offset += sid_size(psd->owner_sid);
     949    }
     950    else
     951      psd->off_owner_sid = 0;
     952
     953    if (psd->grp_sid != NULL)
     954    {
     955      psd->off_grp_sid = offset;
     956      offset += sid_size(psd->grp_sid);
     957    }
     958    else
     959      psd->off_grp_sid = 0;
     960  }
     961
     962  if(!prs_uint32("off_owner_sid", ps, depth, &psd->off_owner_sid))
     963    return false;
     964
     965  if(!prs_uint32("off_grp_sid  ", ps, depth, &psd->off_grp_sid))
     966    return false;
     967
     968  if(!prs_uint32("off_sacl     ", ps, depth, &psd->off_sacl))
     969    return false;
     970
     971  if(!prs_uint32("off_dacl     ", ps, depth, &psd->off_dacl))
     972    return false;
     973
     974  max_offset = MAX(max_offset, ps->data_offset);
     975
     976  if (psd->off_owner_sid != 0)
     977  {
     978    tmp_offset = ps->data_offset;
     979    if(!prs_set_offset(ps, old_offset + psd->off_owner_sid))
     980      return false;
     981
     982    if (ps->io)
     983    {
     984      /* reading */
     985      if((psd->owner_sid = (DOM_SID*)zalloc(sizeof(DOM_SID))) == NULL)
     986        return false;
     987    }
     988
     989    if(!smb_io_dom_sid("owner_sid ", psd->owner_sid , ps, depth))
     990      return false;
     991
     992    max_offset = MAX(max_offset, ps->data_offset);
     993
     994    if (!prs_set_offset(ps,tmp_offset))
     995      return false;
     996  }
     997
     998  if (psd->off_grp_sid != 0)
     999  {
     1000    tmp_offset = ps->data_offset;
     1001    if(!prs_set_offset(ps, old_offset + psd->off_grp_sid))
     1002      return false;
     1003
     1004    if (ps->io)
     1005    {
     1006      /* reading */
     1007      if((psd->grp_sid = (DOM_SID*)zalloc(sizeof(DOM_SID))) == NULL)
     1008        return false;
     1009    }
     1010
     1011    if(!smb_io_dom_sid("grp_sid", psd->grp_sid, ps, depth))
     1012      return false;
    9471013                       
    948                 max_offset = MAX(max_offset, ps->data_offset);
    949 
    950                 if (!prs_set_offset(ps,tmp_offset))
    951                         return false;
    952         }
    953 
    954         if ((psd->type & SEC_DESC_SACL_PRESENT) && psd->off_sacl) {
    955                 tmp_offset = ps->data_offset;
    956                 if(!prs_set_offset(ps, old_offset + psd->off_sacl))
    957                         return false;
    958                 if(!sec_io_acl("sacl", &psd->sacl, ps, depth))
    959                         return false;
    960                 max_offset = MAX(max_offset, ps->data_offset);
    961                 if (!prs_set_offset(ps,tmp_offset))
    962                         return false;
    963         }
    964 
    965         if ((psd->type & SEC_DESC_DACL_PRESENT) && psd->off_dacl != 0) {
    966                 tmp_offset = ps->data_offset;
    967                 if(!prs_set_offset(ps, old_offset + psd->off_dacl))
    968                         return false;
    969                 if(!sec_io_acl("dacl", &psd->dacl, ps, depth))
    970                         return false;
    971                 max_offset = MAX(max_offset, ps->data_offset);
    972                 if (!prs_set_offset(ps,tmp_offset))
    973                         return false;
    974         }
    975 
    976         if(!prs_set_offset(ps, max_offset))
    977                 return false;
    978 
    979         return true;
     1014    max_offset = MAX(max_offset, ps->data_offset);
     1015
     1016    if (!prs_set_offset(ps,tmp_offset))
     1017      return false;
     1018  }
     1019
     1020  if ((psd->type & SEC_DESC_SACL_PRESENT) && psd->off_sacl)
     1021  {
     1022    tmp_offset = ps->data_offset;
     1023    if(!prs_set_offset(ps, old_offset + psd->off_sacl))
     1024      return false;
     1025    if(!sec_io_acl("sacl", &psd->sacl, ps, depth))
     1026      return false;
     1027    max_offset = MAX(max_offset, ps->data_offset);
     1028    if (!prs_set_offset(ps,tmp_offset))
     1029      return false;
     1030  }
     1031
     1032  if ((psd->type & SEC_DESC_DACL_PRESENT) && psd->off_dacl != 0)
     1033  {
     1034    tmp_offset = ps->data_offset;
     1035    if(!prs_set_offset(ps, old_offset + psd->off_dacl))
     1036      return false;
     1037    if(!sec_io_acl("dacl", &psd->dacl, ps, depth))
     1038      return false;
     1039    max_offset = MAX(max_offset, ps->data_offset);
     1040    if (!prs_set_offset(ps,tmp_offset))
     1041      return false;
     1042  }
     1043
     1044  if(!prs_set_offset(ps, max_offset))
     1045    return false;
     1046
     1047  return true;
    9801048}
    9811049
     
    9891057bool sec_ace_equal(SEC_ACE *s1, SEC_ACE *s2)
    9901058{
    991         /* Trivial case */
    992 
    993         if (!s1 && !s2) return true;
    994 
    995         /* Check top level stuff */
    996 
    997         if (s1->type != s2->type || s1->flags != s2->flags ||
    998             s1->info.mask != s2->info.mask) {
    999                 return false;
    1000         }
    1001 
    1002         /* Check SID */
    1003 
    1004         if (!sid_equal(&s1->trustee, &s2->trustee)) {
    1005                 return false;
    1006         }
    1007 
    1008         return true;
     1059  /* Trivial case */
     1060  if (!s1 && !s2)
     1061    return true;
     1062
     1063  /* Check top level stuff */
     1064  if (s1->type != s2->type || s1->flags != s2->flags ||
     1065      s1->info.mask != s2->info.mask)
     1066  { return false; }
     1067
     1068  /* Check SID */
     1069  if (!sid_equal(&s1->trustee, &s2->trustee))
     1070    return false;
     1071
     1072  return true;
    10091073}
    10101074
     
    10191083bool sec_acl_equal(SEC_ACL *s1, SEC_ACL *s2)
    10201084{
    1021         unsigned int i, j;
    1022 
    1023         /* Trivial cases */
    1024 
    1025         if (!s1 && !s2) return true;
    1026         if (!s1 || !s2) return false;
    1027 
    1028         /* Check top level stuff */
    1029 
    1030         if (s1->revision != s2->revision) {
    1031                 return false;
    1032         }
    1033 
    1034         if (s1->num_aces != s2->num_aces) {
    1035                 return false;
    1036         }
    1037 
    1038         /* The ACEs could be in any order so check each ACE in s1 against
    1039            each ACE in s2. */
    1040 
    1041         for (i = 0; i < s1->num_aces; i++) {
    1042                 bool found = false;
    1043 
    1044                 for (j = 0; j < s2->num_aces; j++) {
    1045                         if (sec_ace_equal(&s1->ace[i], &s2->ace[j])) {
    1046                                 found = true;
    1047                                 break;
    1048                         }
    1049                 }
    1050 
    1051                 if (!found) return false;
    1052         }
    1053 
    1054         return true;
     1085  unsigned int i, j;
     1086
     1087  /* Trivial cases */
     1088  if (!s1 && !s2)
     1089    return true;
     1090  if (!s1 || !s2)
     1091    return false;
     1092
     1093  /* Check top level stuff */
     1094  if (s1->revision != s2->revision)
     1095    return false;
     1096
     1097  if (s1->num_aces != s2->num_aces)
     1098    return false;
     1099
     1100  /* The ACEs could be in any order so check each ACE in s1 against
     1101     each ACE in s2. */
     1102
     1103  for (i = 0; i < s1->num_aces; i++)
     1104  {
     1105    bool found = false;
     1106
     1107    for (j = 0; j < s2->num_aces; j++)
     1108    {
     1109      if (sec_ace_equal(&s1->ace[i], &s2->ace[j]))
     1110      {
     1111        found = true;
     1112        break;
     1113      }
     1114    }
     1115
     1116    if (!found)
     1117      return false;
     1118  }
     1119
     1120  return true;
    10551121}
    10561122
     
    10641130bool sec_desc_equal(SEC_DESC *s1, SEC_DESC *s2)
    10651131{
    1066         /* Trivial case */
    1067 
    1068         if (!s1 && !s2) {
    1069                 goto done;
    1070         }
    1071 
    1072         /* Check top level stuff */
    1073 
    1074         if (s1->revision != s2->revision) {
    1075                 return false;
    1076         }
    1077 
    1078         if (s1->type!= s2->type) {
    1079                 return false;
    1080         }
    1081 
    1082         /* Check owner and group */
    1083 
    1084         if (!sid_equal(s1->owner_sid, s2->owner_sid)) {
    1085                 return false;
    1086         }
    1087 
    1088         if (!sid_equal(s1->grp_sid, s2->grp_sid)) {
    1089                 return false;
    1090         }
    1091 
    1092         /* Check ACLs present in one but not the other */
    1093 
    1094         if ((s1->dacl && !s2->dacl) || (!s1->dacl && s2->dacl) ||
    1095             (s1->sacl && !s2->sacl) || (!s1->sacl && s2->sacl))
    1096         {
    1097                 return false;
    1098         }
    1099 
    1100         /* Sigh - we have to do it the hard way by iterating over all
    1101            the ACEs in the ACLs */
    1102 
    1103         if (!sec_acl_equal(s1->dacl, s2->dacl) ||
    1104             !sec_acl_equal(s1->sacl, s2->sacl))
    1105         {
    1106                 return false;
    1107         }
     1132  /* Trivial case */
     1133
     1134  if (!s1 && !s2)
     1135    goto done;
     1136
     1137  /* Check top level stuff */
     1138  if (s1->revision != s2->revision)
     1139    return false;
     1140
     1141  if (s1->type!= s2->type)
     1142    return false;
     1143
     1144  /* Check owner and group */
     1145  if (!sid_equal(s1->owner_sid, s2->owner_sid))
     1146    return false;
     1147
     1148  if (!sid_equal(s1->grp_sid, s2->grp_sid))
     1149    return false;
     1150
     1151  /* Check ACLs present in one but not the other */
     1152  if ((s1->dacl && !s2->dacl) || (!s1->dacl && s2->dacl) ||
     1153      (s1->sacl && !s2->sacl) || (!s1->sacl && s2->sacl))
     1154  { return false; }
     1155
     1156  /* Sigh - we have to do it the hard way by iterating over all
     1157     the ACEs in the ACLs */
     1158  if(!sec_acl_equal(s1->dacl, s2->dacl) || !sec_acl_equal(s1->sacl, s2->sacl))
     1159    return false;
    11081160
    11091161 done:
    1110         return true;
     1162  return true;
    11111163}
    11121164
  • trunk/src/reglookup.c

    r58 r59  
    677677          " <REGISTRY_FILE>\n");
    678678  /* XXX: replace version string with Subversion property? */
    679   fprintf(stderr, "Version: 0.2.1\n");
     679  fprintf(stderr, "Version: 0.2.2\n");
    680680  fprintf(stderr, "Options:\n");
    681681  fprintf(stderr, "\t-v\t sets verbose mode.\n");
Note: See TracChangeset for help on using the changeset viewer.