Remove more uses of "extern struct current_user current_user;".
[ira/wip.git] / source3 / smbd / lanman.c
index 721883f775bd1634da7aedcb9c56b46bc6148e87..4c15f133aec0cab39fe34ffa384c98eacfa30398 100644 (file)
@@ -1351,10 +1351,9 @@ static int fill_srv_info(struct srv_info_struct *service,
 }
 
 
-static bool srv_comp(struct srv_info_struct *s1,struct srv_info_struct *s2)
+static int srv_comp(struct srv_info_struct *s1,struct srv_info_struct *s2)
 {
-#undef strcasecmp
-       return strcasecmp(s1->name,s2->name);
+       return StrCaseCmp(s1->name,s2->name);
 }
 
 /****************************************************************************
@@ -1440,9 +1439,7 @@ static bool api_RNetServerEnum2(connection_struct *conn, uint16 vuid,
        data_len = fixed_len = string_len = 0;
        missed = 0;
 
-       if (total > 0) {
-               qsort(servers,total,sizeof(servers[0]),QSORT_CAST srv_comp);
-       }
+       TYPESAFE_QSORT(servers, total, srv_comp);
 
        {
                char *lastname=NULL;
@@ -1458,7 +1455,7 @@ static bool api_RNetServerEnum2(connection_struct *conn, uint16 vuid,
                        DEBUG(4,("fill_srv_info[%d] %20s %8x %25s %15s\n",
                                i, s->name, s->type, s->comment, s->domain));
 
-                       if (data_len <= buf_len) {
+                       if (data_len < buf_len) {
                                counted++;
                                fixed_len += f_len;
                                string_len += s_len;
@@ -1515,7 +1512,7 @@ static bool api_RNetServerEnum2(connection_struct *conn, uint16 vuid,
        return True;
 }
 
-static bool srv_name_match(const char *n1, const char *n2)
+static int srv_name_match(const char *n1, const char *n2)
 {
        /*
         * [MS-RAP] footnote <88> for Section 3.2.5.15 says:
@@ -1524,7 +1521,7 @@ static bool srv_name_match(const char *n1, const char *n2)
         *  the server will return a list of servers that exist on
         *  the network greater than or equal to the FirstNameToReturn.
         */
-       int ret = strcasecmp(n1, n2);
+       int ret = StrCaseCmp(n1, n2);
 
        if (ret <= 0) {
                return 0;
@@ -1617,9 +1614,7 @@ static bool api_RNetServerEnum3(connection_struct *conn, uint16 vuid,
        data_len = fixed_len = string_len = 0;
        missed = 0;
 
-       if (total > 0) {
-               qsort(servers,total,sizeof(servers[0]),QSORT_CAST srv_comp);
-       }
+       TYPESAFE_QSORT(servers, total, srv_comp);
 
        if (first_name[0] != '\0') {
                struct srv_info_struct *first_server = NULL;
@@ -1637,7 +1632,7 @@ static bool api_RNetServerEnum3(connection_struct *conn, uint16 vuid,
                         */
                        for (;first > 0;) {
                                int ret;
-                               ret = strcasecmp(first_name,
+                               ret = StrCaseCmp(first_name,
                                                 servers[first-1].name);
                                if (ret > 0) {
                                        break;
@@ -1664,7 +1659,7 @@ static bool api_RNetServerEnum3(connection_struct *conn, uint16 vuid,
                        DEBUG(4,("fill_srv_info[%d] %20s %8x %25s %15s\n",
                                i, s->name, s->type, s->comment, s->domain));
 
-                       if (data_len <= buf_len) {
+                       if (data_len < buf_len) {
                                counted++;
                                fixed_len += f_len;
                                string_len += s_len;
@@ -2031,7 +2026,7 @@ static bool api_RNetShareEnum( connection_struct *conn, uint16 vuid,
                if( lp_browseable( i ) && lp_snum_ok( i ) && (strlen(servicename_dos) < 13)) {
                        total++;
                        data_len += fill_share_info(conn,i,uLevel,0,&f_len,0,&s_len,0);
-                       if (data_len <= buf_len) {
+                       if (data_len < buf_len) {
                                counted++;
                                fixed_len += f_len;
                                string_len += s_len;
@@ -3772,7 +3767,9 @@ static bool api_RNetUserGetInfo(connection_struct *conn, uint16 vuid,
                                vuser->server_info->sam_account);
                }
                /* modelled after NTAS 3.51 reply */
-               SSVAL(p,usri11_priv,conn->admin_user?USER_PRIV_ADMIN:USER_PRIV_USER); 
+               SSVAL(p,usri11_priv,
+                       (get_current_uid(conn) == (uid_t)0)?
+                       USER_PRIV_ADMIN:USER_PRIV_USER);
                SIVAL(p,usri11_auth_flags,AF_OP_PRINT);         /* auth flags */
                SIVALS(p,usri11_password_age,-1);               /* password age */
                SIVAL(p,usri11_homedir,PTR_DIFF(p2,p)); /* home dir */
@@ -3825,7 +3822,8 @@ static bool api_RNetUserGetInfo(connection_struct *conn, uint16 vuid,
                memset(p+22,' ',16);    /* password */
                SIVALS(p,38,-1);                /* password age */
                SSVAL(p,42,
-               conn->admin_user?USER_PRIV_ADMIN:USER_PRIV_USER);
+                       (get_current_uid(conn) == (uid_t)0)?
+                       USER_PRIV_ADMIN:USER_PRIV_USER);
                SIVAL(p,44,PTR_DIFF(p2,*rdata)); /* home dir */
                strlcpy(p2, vuser ? pdb_get_homedir(
                                vuser->server_info->sam_account) : "",
@@ -3976,7 +3974,9 @@ static bool api_WWkstaUserLogon(connection_struct *conn,uint16 vuid,
                PACKI(&desc,"W",0);             /* code */
                PACKS(&desc,"B21",name);        /* eff. name */
                PACKS(&desc,"B","");            /* pad */
-               PACKI(&desc,"W", conn->admin_user?USER_PRIV_ADMIN:USER_PRIV_USER);
+               PACKI(&desc,"W",
+                       (get_current_uid(conn) == (uid_t)0)?
+                       USER_PRIV_ADMIN:USER_PRIV_USER);
                PACKI(&desc,"D",0);             /* auth flags XXX */
                PACKI(&desc,"W",0);             /* num logons */
                PACKI(&desc,"W",0);             /* bad pw count */