file_name_hash vs. smb_name_hash

Jeremy Allison jra at samba.org
Wed Jan 26 09:17:09 MST 2011


On Wed, Jan 26, 2011 at 10:07:21AM +0100, Stefan (metze) Metzmacher wrote:
> Hi Jeremy,
> 
> > The branch, master has been updated
> >        via  3272e16 Missed one debug printf of name_hash. Ensure always use %x.
> >        via  4473273 Fix bug #7863 - Unlink may unlink wrong file when hardlinks are involved.
> >        via  a65bce4 Add uint32_t name_hash argument (currently unused) to get_file_infos().
> >        via  b97f1ce Add name_hash into the share mode entry struct (as yet only use for renames to identify a specific path).
> >        via  76418e2 Add name_hash to files_struct. Set within fsp_set_smb_fname().
> >       from  6e22637 s4-test/delete_object: Remove global ldb connections
> > 
> > http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
> 
> > +static uint32_t smb_name_hash(const char *sharepath, const char *filename, int *err)
> > +{
> > +	TDB_DATA key;
> > +	char *fullpath = NULL;
> > +	int ret;
> > +	uint32_t name_hash;
> > +
> > +	*err = 0;
> > +	ret = asprintf(&fullpath, "%s/%s", sharepath, filename);
> > +	if (ret == -1 || fullpath == NULL) {
> > +		*err = 1;
> > +		return 0;
> > +	}
> > +	key.dptr = (uint8_t *)fullpath;
> > +	key.dsize = strlen(fullpath);
> > +	name_hash = tdb_jenkins_hash(&key);
> > +	free(fullpath);
> > +	return name_hash;
> > +}
> > +
> 
> > +NTSTATUS file_name_hash(connection_struct *conn,
> > +                       const char *name, uint32_t *p_name_hash)
> > +{
> > +       TDB_DATA key;
> > +       char *fullpath = NULL;
> > +
> > +       /* Set the hash of the full pathname. */
> > +       fullpath = talloc_asprintf(talloc_tos(),
> > +                       "%s/%s",
> > +                       conn->connectpath,
> > +                       name);
> > +       if (!fullpath) {
> > +               return NT_STATUS_NO_MEMORY;
> > +       }
> > +       key = string_term_tdb_data(fullpath);
> > +       *p_name_hash = tdb_jenkins_hash(&key);
> > +
> > +       DEBUG(10,("file_name_hash: %s hash 0x%x\n",
> > +               fullpath,
> > +               (unsigned int)*p_name_hash ));
> > +
> > +       TALLOC_FREE(fullpath);
> > +       return NT_STATUS_OK;
> > +}
> 
> These function don't calculate the same hash!
> string_term_tdb_data() uses strlen()+1.

Got it - thanks ! I'll fix asap !

Jeremy


More information about the samba-technical mailing list